G
Guest
Hello,
I'm trying to create a C++ command line program that will extract specific
lines from a text file and write them to another text file. E.g. If I want
the program to look for the word "The"(Always at the start) and extract the
entire line.
Text file input example:
// ------------------------
Hello there!
The quick brown fox
Jumped over the
lazy dog
The pizza arrived
on time
// ------------------------
Would output
The quick brown fox
The pizza arrived
I know this can be done with VB using strings and InStr. I've found that
strings can be examined using
string.find(word to find);
However, when reading data from a file, I don't seem to be able to use a
string to put the data read from a file into.
I've tried using
// -------
ifstream filein;
filein >> variable;
// And
filein.read(variable, character-limit);
// -------
Neither appears to accept using a string variable as a variable for that, I
can get it to work as a char, double, etc; but when I use char I stops at
spaces and ignores the ends of lines.
Thank you,
Andy.
I'm trying to create a C++ command line program that will extract specific
lines from a text file and write them to another text file. E.g. If I want
the program to look for the word "The"(Always at the start) and extract the
entire line.
Text file input example:
// ------------------------
Hello there!
The quick brown fox
Jumped over the
lazy dog
The pizza arrived
on time
// ------------------------
Would output
The quick brown fox
The pizza arrived
I know this can be done with VB using strings and InStr. I've found that
strings can be examined using
string.find(word to find);
However, when reading data from a file, I don't seem to be able to use a
string to put the data read from a file into.
I've tried using
// -------
ifstream filein;
filein >> variable;
// And
filein.read(variable, character-limit);
// -------
Neither appears to accept using a string variable as a variable for that, I
can get it to work as a char, double, etc; but when I use char I stops at
spaces and ignores the ends of lines.
Thank you,
Andy.