D
Dave Reid
Hi everyone...
I'm pretty much a newbie C++ user, and I've run into a problem.
I'm trying to read in a large text file, and then do manipulations on
it. I can read it into a large 2-dimensional character array, but I'd
really like to read it into a vector of strings. Here's how I'm doing
the read into the char array:
int main() {
string str1("booger");
string str2("test");
int index = 0;
char buffer[256]; //two dimensional string
array
char buff2[1000][256]; // 1K lines, 256
chars each
ifstream examplefile ("example.txt"); //test file
if (! examplefile.is_open()) //check to make
sure file can be opened
{ cout << "Error opening file"; exit (1); }
cout << str1 << "\n\n";
while (! examplefile.eof() ) //do until end of
file is reached
{
examplefile.getline (buff2[index],100); //get the
line, put into buffer
cout << "buffer:" << buff2[index] << endl; //print out
the contents of buffer
index = index + 1;
}
return 0;
}
So that works out great...but I'm not sure how I'd modify that to
replace the char buffer[] with a string vector. Any hints for me?
Thanks in advance...
dave
I'm pretty much a newbie C++ user, and I've run into a problem.
I'm trying to read in a large text file, and then do manipulations on
it. I can read it into a large 2-dimensional character array, but I'd
really like to read it into a vector of strings. Here's how I'm doing
the read into the char array:
int main() {
string str1("booger");
string str2("test");
int index = 0;
char buffer[256]; //two dimensional string
array
char buff2[1000][256]; // 1K lines, 256
chars each
ifstream examplefile ("example.txt"); //test file
if (! examplefile.is_open()) //check to make
sure file can be opened
{ cout << "Error opening file"; exit (1); }
cout << str1 << "\n\n";
while (! examplefile.eof() ) //do until end of
file is reached
{
examplefile.getline (buff2[index],100); //get the
line, put into buffer
cout << "buffer:" << buff2[index] << endl; //print out
the contents of buffer
index = index + 1;
}
return 0;
}
So that works out great...but I'm not sure how I'd modify that to
replace the char buffer[] with a string vector. Any hints for me?
Thanks in advance...
dave