Code not working - help

The "assigns" in the following code is not working. I don't know if assigns is what i should be using. I need to retrieve characters from line1. The variables: last, xxpos, eqpos contain certain position numbers in string line1. Any help is much appreciated. Thanks.


1
2
3
4
5
6
7
8
9
getline( reader , line1 ) ;
	 last = line1.length() ;
	 xxpos = line1.find( "x", 0 ) ;
	 eqpos = line1.find( "=", 0 ) ;
	 num1.assign( 0, line1.at(xxpos) - 1  ) ;
	 numx.assign( line1.at(xxpos), line1.at(xxpos) ) ;
	 num2.assign( line1.at(xxpos) + 1, line1.at(eqpos) - 1 ) ;
	 numeq.assign( line1.at(eqpos), line1.at(eqpos) ) ;
	 num3.assign( line1.at(eqpos) + 1, line1.at(last) - 1 ) ;
closed account (o3hC5Di1)
Hi there,

Try rewriting those assign lines as the following:

num1 = line1[xxpos-1];

If num1 is an integer variable, you may have to use a function such as atoi().
http://cplusplus.com/reference/clibrary/cstdlib/atoi/

Hope that helps.

All the best,
NwN
Topic archived. No new replies allowed.