file IO with structure
Nov 30, 2014 at 1:02am UTC
I'm having a problem reading a structure from a file, but it works fine saving to a file.
I get the error in line 31 saying "error C2678: binary '>>' : no operator found which takes a left-hand operand of type..." and a whole bunch of weird stuff.
Anyone help me?
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
void writeFile()
{
ofstream file;
file.open("test.txt" );
if (!file)
{
cout << "Cannot load file, aborting." << endl;
exit(0);
}
else
{
file << u1.name << " " << u1.phoneNumber << " " << u1.servicePin;
file.close();
}
}
void readFile()
{
ifstream file1;
file1.open("test.txt" );
if (!file1)
{
cout << "Cannot load file, aborting." << endl;
exit(0);
}
else
{
file1 >> u1.name >> " " >> u1.phoneNumber >> " " >> u1.servicePin;
file1.close();
}
}
Nov 30, 2014 at 1:10am UTC
what do you think file>>" " ;
mean?
You should fix your code if you realize this.
Nov 30, 2014 at 1:13am UTC
I'm trying to space it out
Nov 30, 2014 at 1:36am UTC
No. If you want to space it out,
file>> u1.name >> u1.phoneNumber >> u1.servicePin;
or better space
1 2 3
file>>u1.name
>>u1.phoneNumber
>>u1.servicePin;
When you do
file>>" "
, you are trying to put something in
" "
which of course you know is wrong because
" "
is not a variable.
Last edited on Nov 30, 2014 at 1:37am UTC
Topic archived. No new replies allowed.