Mar 20, 2012 at 2:37pm UTC
this doesnt help much i tried it but there is nothing that make sense
isnt there a simple command to stop reading after an EOL char is detected?
Mar 20, 2012 at 3:39pm UTC
You can use getline function with '\n' as delimiter character!
i.e:
infile.getline ( name,size,'\n');
Mar 20, 2012 at 4:35pm UTC
tried
didnt work now it doesnt print anything
Mar 20, 2012 at 11:31pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
int main()
{
const int size=50;
char name[size];
char name2[size],in[size];
int number=0,counter=0,length=0;
ifstream infile;
ofstream outfile ("dataOut" , ios::out);
cout<< "Please enter file name: " ;
cin>> in;
infile.open(in);
infile>>number;
cout<<number<<endl;
if (infile) {
infile.get(name,size,'\0' );
cout<<name;
}
}
Your mistake was:
1 2 3
while (infile) {
infile.get...
}
While your file contains characters, you KEEP on printing them out, line by line.
What i did is changing your WHILE into an IF, so IF your file contains characters, you print ONE line from the file.
Last edited on Mar 20, 2012 at 11:32pm UTC