当前位置:网站首页>Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();

Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();

2022-07-07 05:59:00 Grow your own flowers 111

C++ Medium  to_string() The series of functions will Convert numeric values to strings form .

The header file :#include<string>

string s = to_string(n); // The integer n Convert to string String representation

to_string() The prototypes of all functions are as follows :

string to_string (int val);
string to_string (long val);
string to_string (long long val);
string to_string (unsigned val);
string to_string (unsigned long val);
string to_string (unsigned long long val);
string to_string (float val);
string to_string (double val);
string to_string (long double val);

Example :

#include <iostream>
#include <string>
using namespace std;
int main() {
		int a = 4876867;
		string str= to_string(a);
		cout << str;
		return 0;
	}
	

  After operation :

character string str=4876867;

take String conversion to int Type sharp weapon stoi();

stoi();

#include <iostream>
#include <string>
using namespace std;
	int main() {
     string a="15135";
      int n=stoi(a);
     cout<<n;
	}

  Output n=15135;

原网站

版权声明
本文为[Grow your own flowers 111]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130724467753.html