I want to read the last two characters from each string in the array, which in this case are 25 and 39 and then put them in a separate array like this..
array_integers = 25;
array_integers = 39;
the end of every string will have a integer thats why the second array is of type int.
I am kind of stuck on this part. Any suggestions would be greatly appreciated. Thanks in advance.
Isolate (using whatever method you like) the last two char of each string as a substring and then convert the substring to an int (using whichever method you prefer). There are at least two ways to do each the isolation and the conversion.
you should be able to use the substr() method to isolate the last two char of the string and you should be able to use a stringstream to convert the string isolated by substr() to an int. Both substr() and stringstream are standard C++ items.
hey thanks. Substring worked quite well. I have another question. rather silly to ask but is it possible to print a integer as a string?
like int val = 1;
if we cout<<val its gonna put out 1...but is there a way that it represents 1 yet prints out it self? so cout<<val should print val insted of 1 lol..
There is no routine way to print a variables name. You could create a user defined type and include the name of the type as one of the data members. However, the name of the variable itself, not that I can think of.
It is possible to use numerical values as either numerical variables or string variables and it is possible to convert the value of numerical variables into strings or strings representing numerical values into numerical values.
int i = 1;
string strI = "1";
cout << i << " or " << strI;
will print out: 1 or 1. You can't tell which 1 is an int and which 1 is a string to look at them on the screen or in a file, etc.