-
Text file
I've got a text file that I need to output to the screen. The text file contain's blank lines, which also need to be outputted to the screen. The code which i'm using at the mo is:
Code:
while(!File.eof())
{
File.getline(Buffer,100)
cout << Buffer;
}
File >> ws;
getchar();
Getline is just ignoring blank lines, and going onto the next bit of data.
-
Are you sure? Try a newline on your cout to be sure.
cout << Buffer << endl;
-
Tried a new line, still does the same. Debugger shows getline ignoring the any blank lines.
-
getline's default deliminating character is \n
instead try file.getline(Buffer, 100, EOF);
not sure if EOF can be used this way or not
-
/*file*/
8/8/2002
1 2 3 4
//reading file
char filename[] = //whatever;
ifstream fin(filename);
char ws;
char buffer[12];
int array[4];
while(!fin.eof())
{
fin.getline(buffer, 11);//ignore newline at end of first line
fin >> ws;//store second new line in ws
for (int i = 0; i < 4; i++)
{
fin >> array[i];
}
}
or read entire file in one char at a time
char ch;
char buffer[50];
int i = 0;
while(fin.get(ch) && i < 50)
{
buffer[i++] = ch;
}