You're very close now! As you say, line_number is the line number, not the actual line. But you are reading in the actual line into string line using the getline function. So all you have to do is use line rather than line_number when you are trying to access the actual line rather than the number.
Also, it looks to me that line 44 and lines 46 to 51 are no longer needed by your program. They are half completed repetitions of previous pieces of code. If you look closely, I'm sure you'll see this.
Sorry I didnt see that you posted a message.Nevertheless I corrected the problem with line_number.See my previous post, I edited it.
Can you repeat which lines?line 44 is empty and there are only 48 lines?
p.s.Oh I think it was a repeated code, I made a mistake and deleted it, may be those were the pointless lines.
Any idea for the errors?
I think the code is correct.How its possible to be wrong.Or may be I am too tired to see just a stupid mistake...
OK. The problem, I think is with the line infile.getline(line);.
Basically, this function reads data into a char* variable rather than an std::string one.
Originally, however, you used this instead: getline (myfile,line); (I think you got this from the file I/O tutorial).
I told you to change from getline(myfile, line) to infile.getline(line). Turns out you did in fact want getline(myfile, line - my bad :P
Anyway, if you change infile.getline(line) back to getline(infile, line) then the problem should be fixed.
In summary, this is because std::ifstream::getline (i.e. infile.getline) reads a line into a char* variable, which you do not want. On the other hand, std::getline (i.e. getline) reads the line into a string - which is what you want.
The compiler error is basically telling you this - that it is finding a string variable where it expects a char*.
Yeah I may not have explained everything as clearly as I ought have...
You need an array
However, I believe the OP wanted her program to scan through a file to the n th line and display it on standard output in reverse order. Thus it is unnecessary to keep track of every line with an std::vector. I believe Jennifer wants to display the n th line in reverse order, rather than the whole file.
See earlier, where The OP said:
So what i want to do is to make a program which asks the user to input a number of a line.So the user chooses line 3.The program should take line number 3 from a file with name for example "example.txt", to reverse it and to display it.Thats all