convert a string to int this way.
string test = "1234" ;
istringstream stm(test);
int num = 0;
stm >> num ;
// if using boost (boost lexical cast), it is easier
num = boost::lexical_cast<int>(test) ;
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
>Does it have something to do with how I got scores?
It probably has something to do with returning an int from a function that's defined to return a string... Also, your function probably doesn't do what you want. Can you describe what you think it should be doing?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
That gave the same error as before. Does it have something to do with how I got scores? And I would rather not use boost.
i just tested the code (which i posted). compiles in both vc++ 8.0 and gcc 3.4.6. also works correctly in both.
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
You should probably post a working code here along with the explanation of what it does. Making us guess what your code does is not a good idea. Post the complete code (along with main) along with the sample input data supplied and the expected output.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
if you just want the sum, this would be simpler:
int sum2(string line)
{
istringstream stm(line) ;
string x ; stm >> x >> x ;
int sum=0 ; int n = 0 ;
while( stm >> n ) sum += n ;
return sum ;
}
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287