May 12, 2009 at 1:09pm UTC
The problem is that argv[i+1]
contains chars and the char '2' has not the value 2. You can convert the char by unsing atoi:
if ( ss == atoi(argv[i+1] )
May 12, 2009 at 1:14pm UTC
ss is a stringstream, argv[i+1] is a pointer to char.
You should also convert argv[i+1] to a number
1 2 3 4 5 6 7
if (ss >> line_number)
{
cout << "line: " << line << ", line_number: " << line_number
<< ", argv[(i + 1)]: " << argv[(i + 1)] << endl;
if (line_number == atoi ( argv[(i + 1)] ) ) // Notice: the number you are comparing is 'line_number', not 'ss'
cout << line << endl;
}
atoi (
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/ ) is a C library function, if you want to be more C++, you should use another stringstream or the boost library
http://www.cplusplus.com/forum/articles/9645/
EDIT: mordekai typed faster than me
Last edited on May 12, 2009 at 1:16pm UTC
May 12, 2009 at 1:18pm UTC
Wow, thanks a lot guys, il try this tomorrow (got to go out now)
Thanks very much for all your replies, il let you know if I have any other problems :)
May 12, 2009 at 1:24pm UTC
And Bazzy is correct. You should compare line_number, not ss, to atoi( argv[i+1] )