I am new to c++ coming from Visual basic and I know there has GOT to be an easy way to convert a string to an integer (i.e. something like the Visual Basic "VAL" command
(x=val(string))) but I can't find it in my books or online. Here is an example of what I would like to do.
#include <iostream>
#include <string>
using namespace std;
string age = "";
int age2 = 0.0;
int main()
{
cout << "Enter your age ";
getline (cin,age);
convert the info in string age to the integer age2 here
cout << age2;
return 0;
}
Yes I know I could use cin or put it directly into the int age2 - this is just a sample - what I actually have is a program that is reading several strings from disk and then one integer - I would like to input them all into a string, then just convert the one that is a number to an int. HELP!!!!!!!
Thanks
(x=val(string))) but I can't find it in my books or online. Here is an example of what I would like to do.
#include <iostream>
#include <string>
using namespace std;
string age = "";
int age2 = 0.0;
int main()
{
cout << "Enter your age ";
getline (cin,age);
convert the info in string age to the integer age2 here
cout << age2;
return 0;
}
Yes I know I could use cin or put it directly into the int age2 - this is just a sample - what I actually have is a program that is reading several strings from disk and then one integer - I would like to input them all into a string, then just convert the one that is a number to an int. HELP!!!!!!!
Thanks