Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

string to integer convert c++

#include <iostream>
#include <string>
using namespace std;

int main() {
   // a string variable named str
   string str = "7";
   //print to the console
   cout << "I am a string " << str << endl;

   //convert the string str variable to have an int value
   //place the new value in a new variable that holds int values, named num
   int num = stoi(str);
   
   //print to the console
   cout << "I am an int " << num << endl;
}
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #string #integer #convert
ADD COMMENT
Topic
Name
1+5 =