-
File Reading Problem
Hello, everyone. Like to thank all those who took the time to look at this thread. I'm in need of some assitance. I'm trying to get a program to read from the second line instead of the first line of a txt file. Here is what I have so far:
Code:
#include <iostream.h>
#include <fstream.h>
int main()
{
char a[200];
ifstream inFile("a:\\joey.txt", ios::in);
inFile.get(a,200);
cout<<a<<endl;
inFile.close();
}
That makes it get from the first line. But everything I've tried to make it read from the second instead, hasn't worked. So can anyone help me out?
-
the post what u have done is not relavent to this board. this is 'C' board form.
s.s.harish
-
-
try this:
Code:
#include<iostream> //standards-compliant header
#include<fstream> //same as above
int main()
{
char*line=new char[256];
std::fstream file("Untitled1.dat",std::ios::in);
file.ignore(32000,'\n'); //ignore 32k chars, or up to '\n'
file.getline(line,256,'\n'); //take in the next line, up to 256 chars
std::cout<<line; //output the line
std::cin.get(); //wait for user input
return 0;
}