User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » C++ n00b Page [1]  
jaZon
All American
27048 Posts
user info
edit post

Ok, I need to read all the lines from a file and run a custom search in each line.

Fine.

int main(int argc, char* argv[])
{

char* pattern = argv[1];
string line;
ifstream myFile(argv[2]);

if (myFile.is_open())
{
while (!myFile.eof())
{
getline(myFile,line);
if (search(pattern, line) == true)
{
cout << "yep";
}
}
myFile.close();
}
}


The search function is defined as:

bool search(char pattern[], char text[]);


Problem being it won't compile due to the type mismatch.

Quote :
" error: cannot convert `std::string' to `char*' for argument `2' to `bool search(char*, char*)""


Help?

9/21/2006 8:58:03 PM

BigMan157
no u
103352 Posts
user info
edit post

you need to tokenize the string

or just include the string class and use the find() function
http://www.linuxselfhelp.com/HOWTO/C++Programming-HOWTO-7.html

[Edited on September 21, 2006 at 9:10 PM. Reason : is parse and tokenize the same thing?]

9/21/2006 9:05:44 PM

jaZon
All American
27048 Posts
user info
edit post

convert string to char?

9/21/2006 9:09:27 PM

30thAnnZ
Suspended
31803 Posts
user info
edit post

geez

it's no wonder we never holla'd at bitches

9/21/2006 9:23:48 PM

jaZon
All American
27048 Posts
user info
edit post

const_cast<char*>(line.c_str()))

and there are no compiler errors

and thanks for bringing that up

9/21/2006 9:27:24 PM

skokiaan
All American
26447 Posts
user info
edit post

why are you not using perl?

9/22/2006 1:21:07 AM

 Message Boards » Tech Talk » C++ n00b Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.