- #1
yungman
- 5,755
- 292
I have been reviewing Chapter 12 files. From experiment,
Below, when I said doesn't work, I mean VS gave me a compile error. But if I tell compiler to just run it, it seems to work.
I found if I try to read a file into string, only line13 getline(dataF, Crstr) works. line 14 dataF.getline(Crstr,size) flag error no matter how I tried.
The opposite is true if I read the file into an array, getline(dataF,Ar) flag error and only dataF.getline(Ar, sizeof(Ar)) works.
The book only talk about dataF.getline with Array, I learn getline(dataF,Crstr) here or online. Is my finding valid?
Thanks
C++:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
char Ar[] = "demofile.txt";
string Cwstr, Crstr;
char cAr[100];
int size = 100;
fstream dataF;
dataF.open(Ar, ios::in);
getline(dataF, Crstr);
//dataF.getline(Crstr, size);
cout << Crstr << "\n\n";
dataF.close();
return 0;
}
Below, when I said doesn't work, I mean VS gave me a compile error. But if I tell compiler to just run it, it seems to work.
I found if I try to read a file into string, only line13 getline(dataF, Crstr) works. line 14 dataF.getline(Crstr,size) flag error no matter how I tried.
The opposite is true if I read the file into an array, getline(dataF,Ar) flag error and only dataF.getline(Ar, sizeof(Ar)) works.
The book only talk about dataF.getline with Array, I learn getline(dataF,Crstr) here or online. Is my finding valid?
Thanks