I simply want to print out a set of integers, that are written down one on each line in a text file. Since I am using Linux, I cannot seem to use convenient functions like getch() and getline()
Please read my code below and tell me what I need to change to see the integers in the text file
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream fp;
fp.open("/home/Documents/C/Codeblocks/test1.txt", ios::in);
int c;
if(!fp)
{
cout<<"Cannot open file\n";
return 1;
}
while(fp)
{
fp.get(c);
cout << c;
}
//while ((c = getline(fp) != EOF))
// printf("%d\n", c);
}
getlinewill work also on linux. It's standard C++. Just pass the right arguments to it. (Hint: getline does not return as you expected)