Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Reading Specific Lines in C++
Name: Larry Date: August 10, 2002 at 20:11:56 Pacific
Comment:
I want to be able to read a specific line from a file in C++. I currently have a program that goes like this:
char name[20]; int main(int argc, char *argv[]) { cout << "Please enter your name: "; ofstream examplefile ("example.txt", ios::out | ios::trunc); cin.getline (name, 20); examplefile << name; examplefile.close();
return 0; }
And so far, it compiles fine but I want to be able to read and write to a specific line in the text document. Such as when the user enteres their name it would be written to line 2 instead of the top line and then I would like to be able to read from line 2 specifically later on in the program.
Name: peter4u Date: August 11, 2002 at 14:50:36 Pacific
Reply:
You are actually asking for a database solution with a table and an index. The next question is, if you are going to use a fix or variable record length and how do you map the name to get an unique index.
If that's all too complicated, you may just want to stick with with your sequential search.
0
Response Number 2
Name: Shani Khan Date: August 17, 2002 at 03:36:56 Pacific
Reply:
someone told me a question that make a C++ program in which user can read the data from data in file,whose first line has an integer value that show that how many next line s you have to read.And every line has two integer values and display,you have to find the maximum of those,both values and display the input values and the maximum of both.
Summary: Hi ! I Im trying to add some text to a txt file like this: echo blablabla >>mu.txt But I dont want the text to be added in the beginning of the file. I want to add the text to a specific line in the t...
Summary: hi, is there any way to find a specific line in a txt/ini/inf file, alter that line from the batch file and save the edited file? example: the file blabla.ini contains this line somewhere: DefaultFOV=...
Summary: Hi, I would like to read a specific line from a file by compaq visual FORTRAN. The line is at the near middle of the file. Please provide some necessary suggestion to solve this problem. For sake of c...