ifstream doesn't print the whole file

Hello

i am using ubuntu 14.04 and codeblocks 13.2.

When i enter the code below all i get is the four first lines of the files:

<output>

chair 0
ninja -54
fruit 43
shoe 0

</output>

am i doing something wrong?

thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
    short effect=0;
    string things;.
  ofstream thefile("Objects.txt");

  if (thefile.is_open())
  {
      thefile<<"chair 0"<<endl;
      thefile<<"ninja -54"<<endl;
      thefile<<"fruit 43"<<endl;
      thefile<<"shoe 0"<<endl;
      thefile<<"pen o"<<endl;
      thefile<<"cake 87"<<endl;
      thefile<<"soda 32"<<endl;
      thefile<<"meth -44"<<endl;
      thefile<<"Dirtyneeĵdle -99"<<endl;

      thefile.close();
  }

  ifstream thefile2("Objects.txt");

  while (thefile2 >> things >> effect)
  {
    cout<<things<<" "<<effect<<endl;
  }


 return 0;
}
Last edited on
Line 19: "pen o". You write 'o', a character. An attempt to read a character into short fails.
thanks a lot keskiverto that fixed the problem.
Topic archived. No new replies allowed.