string类型转换int类型
来源:互联网 发布:照片说话软件 编辑:程序博客网 时间:2024/05/01 17:55
C++转换形式(C++11):
int main(int argc, char* argv[]){ std::string str1 = "45"; std::string str2 = "3.14159"; std::string str3 = "31337 with words"; std::string str4 = "words and 2"; int myint1 = std::stoi(str1); int myint2 = std::stoi(str2); int myint3 = std::stoi(str3); // error: 'std::invalid_argument' /*int myint4 = std::stoi(str4);*/ std::cout << "std::stoi(\"" << str1 << "\") is " << myint1 << '\n'; std::cout << "std::stoi(\"" << str2 << "\") is " << myint2 << '\n'; std::cout << "std::stoi(\"" << str3 << "\") is " << myint3 << '\n'; /*std::cout << "std::stoi(\"" << str4 << "\") is " << myint4 << '\n';*/}
output:
std::stoi("45") is 45std::stoi("3.14159") is 3std::stoi("31337 with words") is 31337
同样, 可以使用 stol(long), stof(float), stod(double) 等.
0 0
- string类型转换int类型
- string类型转换int类型
- string, char*, int类型转换
- string, char*, int类型转换
- int转换成string类型
- String与int类型转换
- int、String的类型转换
- string, char*, int类型转换
- string to int ... 类型转换
- int、String等类型转换
- String int类型相互转换
- int、String的类型转换
- int与string类型转换
- int与string类型转换
- String转换为int类型
- C++ int类型转换string类型
- string类型与int类型的转换
- 将String类型转换成int类型
- POJ - 2387Til the Cows Come Home
- ContextMenuStrip 类
- 在WPF中使用WinForm控件方法
- WPF中弹出菜单
- WPF菜单
- string类型转换int类型
- 授予组件和控件许可权限
- WPF相关开源项目
- WPF获取应用程序启动目录的方法
- WPF 中的image控件的Source如何赋值
- Bzoj 2038: [2009国家集训队]小Z的袜子(莫队)
- Unhandled Exception:System.DllNotFoundException: Unable to load DLL"**":找不到指定的模块
- C#SMTP发邮件
- WPF:MVVM模式下ViewModel关闭View