where to mention the line i want from txt file...
Jan 26, 2012 at 6:40am UTC
i want the user to provide detail about the line and the program to provide the total line please help . i have tried many things but it shows some part or whole of the file...
Jan 26, 2012 at 8:22am UTC
Not sure if I understand your question but here is code to print a specific line in a text file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream>
#include <string>
#include <fstream>
#include <limits>
int main()
{
std::ifstream in("filename" );
int lineNumber;
std::cout << "What line number do you want to show? " ;
std::cin >> lineNumber;
for (int i = 0; i < lineNumber; i++)
{
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n' );
}
std::string line;
std::getline(in, line);
std::cout << "Line " << lineNumber << ": " << line << std::endl;
}
Jan 26, 2012 at 8:25am UTC
thanks peter87 actually i wanted the user to give some information about the line....
Jan 26, 2012 at 8:35am UTC
+ it says numeric_limits is not a member of std :\
Jan 26, 2012 at 8:36am UTC
Did you include <limits>?
Topic archived. No new replies allowed.