-
File IO (txt file)
How do I read information from a certain line from a txt file in as a char, and then edit it.
This my code, but it doesn't work? Can someone please help as File IO is one of my weaker areas of C++..
Code:
char replacement[10];
int x;
int lines =;
char buffer[256];
cout << "Please Enter the line you would like to edit: ";
cin >> x;
endl;
cout << "Line " << x << " curently reads ";
endl;
ifstream afile (managerfile);
afile.getline (buffer,100);
while(afile.getline (buffer,100))
{
if(lines==x) cout << buffer;
else cout << "Line " << x << " does not exsist";
}
afile.close();
endl;
cout << "Replace with: ";
cin >> replacement;
endl;
ofstream bfile (managerfile, ios::app);
while(bfile.getline (buffer,100))
{
if(lines==x);
bfile<<replacement;
}
bfile.close();
cout<<"Line Succesfully Edited";
Also can someone explain what the 100 after (buffer, is refering to?
Thanks.
-
There is LOTS of information on this topic on the FAQ board, and a comprehensive tutorial to this in the tutorials section of the main site.
http://www.cprogramming.com/tutorial.html
-
Cheers Kermi
But I've read through the tutorials about file io and search the net but cann't find any info on how to goto to specific line in a txt file and then edit it??
:(
:confused: