qt-interest@trolltech.com
[Top] [All Lists]

Re: File read problem

Subject: Re: File read problem
From: "Duane Hebert"
Date: Wed, 28 Feb 2007 18:54:02 -0500
"Srikanth Bemineni" <sbemineni@xxxxxxxxxxxx> wrote in message 
news:45E6180B.5080807@xxxxxxxxxxxxxxx
>I even tried that It doesn't work.I dont know what's the problem.

OK, I fixed a couple of typoes and this actually compiles and
runs.  Copy your file to c:/test.txt (if your using windows
of change the filename if you're not)

I used it to open a 115000 line text file with
no problem.  If it doesn't display all of your lines,
put a break point on the push_back and find the
last line that it reads and start debugging it.

#include <string>
#include <vector>
#include <fstream>
#include <iostream>
using namespace std;
int main() {
ifstream infile("c:/test.txt");
if(!infile.is_open()) return 1;
string buffer;
vector<string> vec;
while(getline(infile,buffer)) {
vec.push_back(buffer);
}
int x = vec.size();
for(std::vector<string>::iterator it = vec.begin(); it != vec.end(); ++it)
cout << *it << "\n";
system("pause");

return 0;
} 


--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>