>cin.getline(linebuffer,100);
This should be
file.getline(linebuffer,100);
The program is stopping dead in its tracks because the loop is keyed on whether the file is empty or not, and you never read from the file, just standard input.
Also, using eof() as a loop condition is wrong because the eofbit is only set for the streamafter you try and fail to read. This will usually cause the loop to iterate one more time than you expect.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Don't forget to read all of my post. Your code has a subtle bug that needs to be fixed.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
A new [post=155265]tip[/post] for you and those who will follow.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
#include <iostream>
#include <fstream>
int main()
{
std::ifstream file("file.txt");
if ( file )
{
int c;
while ( (c = file.get()) != EOF )
{
std::cout << static_cast<char>(c);
}
}
return 0;
}
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314