strange..how come..i eve did this read.getline(line, 100 '\n'); still no work
Last edited on
LOL. I think it is because your text file is stored in Windows format but you are compiling in *nix. Am I right?
The text file is
"hello\r\nworld\r\n"
So your program reads each line as: "hello\r" and "world\r". (Try a file with a longer first line.)
JSYK, there is no reason you can't (and shouldn't) be using
std::string to handle I/O. Also, don't loop on EOF.
1 2 3 4 5 6 7
|
string s;
ifstream f( filename );
while (getline( f, s ))
{
cout << s << "\n";
}
|
Hope this helps.
[edit] Once you've got the data in a std::string, you can copy it to your char array in your struct.
|
strcpy( records[n].line, s.substr( 0, max_records_line_size - 1 ).c_str() );
|
Last edited on
You can check by opening a terminal and typing
od -c foo.txt
(replace foo.txt with whatever your file is named.)