Re: help old VBasic programmer with simple file read , Please :)
On Jun 14, 6:30 am, Rolf Magnus <ramag...@t-online.de> wrote:
marks542...@yahoo.com wrote:
I have a program in Basic that reads a file , looks for lines
containing a specific string , and lists them.
I am trying to do the same thing in C in a search for speed
with very large files.
If speed is a criteria, you may have to write your own. None of
the standard library functions will do a BM search, for example.
I have a program working until I try testing for the substring.
heres the code I have:
[...]
char str[] = "Geom";
int main(int argc, char* argv[])
{
string line;
char *pdest;
ifstream myfile ("C:\\Documents and Settings\\Owner\\My Documents\
\downloads\\stimuli\\stimV4wall2.pz2");
if (myfile.is_open())
{
while (! myfile.eof() )
This loop is incorrect. See question 15.5 in the "C++ FAQ lite".
{
getline (myfile,line);
pdest = strstr( line, str );
Why aren't you using std::string::find?
Or std::search. I'd declare the search string as an std::string
as well, and merge this and the following line into something
like:
if ( std::search( line.begin(), line.end(), str.begin(),
str.end() )
!= line.end() ) {
// ...
}
Somehow, it seems more idiomatic.
--
James Kanze (GABI Software, from CAI) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34