Why not use fgetc? I don't really use C++ constructs, so in C it would be (and I'm just writing this on the fly so expect some errors):
#include
#include
int main() {
char myChar;
FILE *in = fopen("myfile.txt", "r"); // Open myfile.txt read-only
while((myChar=fgetc(in)) != EOF) {
if(myChar=='\n') printf("\n");
else printf("%c",myChar);
}
return 0;
}
File: myfile.txt
this is
data
hehe
%./a.out
this is
data
hehe
If you want to break after the first line:
#include
#include
int main() {
char myChar;
FILE *in = fopen("myfile.txt", "r"); // Open myfile.txt read-only
while((myChar=fgetc(in)) != EOF) {
if(myChar=='\n') {
printf("\n");
break;
} else printf("%c",myChar);
}
return 0;
}