日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

C++實(shí)現(xiàn)字符串和整數(shù)的相互轉(zhuǎn)換_C 語(yǔ)言

作者:Kinght_123 ? 更新時(shí)間: 2023-02-07 編程語(yǔ)言

字符串轉(zhuǎn)換整數(shù)

方法1

#include <iostream>
#include <typeinfo>

using namespace std;

int main() {
	string s = "Kinght_123";
	cout << typeid(s).name() << '\n';
	cout << typeid(atoi(s.c_str())).name();

	return 0;
}

輸出:

方法2(推薦)

首先需要引入頭文件#include <string>

#include <iostream>
#include <typeinfo>
#include <string>

using namespace std;

int main() {
	string s = "Kinght_123";
	cout << typeid(s).name() << '\n';
	cout << typeid(stoi(s)).name();

	return 0;
}

輸出:

整數(shù)轉(zhuǎn)換字符串

需要引入頭文件#include <string>

#include <iostream>
#include <typeinfo>
#include <string>

using namespace std;

int main() {
	int s = 666;
	cout << typeid(s).name() << '\n';
	cout << typeid(to_string(s)).name();

	return 0;
}

輸出:

原文鏈接:https://blog.csdn.net/Kinght_123/article/details/128520784

欄目分類
最近更新