C++ stringstream(强制类型转换)
2018-03-08 11:50
169 查看
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(int argc,char** argv){
int value_int = 111;
double value_double = 1.11;
string value_string = "111";
bool value_bool = true;
stringstream ss;
ss.clear(); //int<--->double之间的转换
ss << value_int;
double temp_double = 0.00;
cout << temp_double << "\t";
ss >> temp_double;
cout << temp_double << endl;;
ss.clear(); //int<--->string之间的转换
ss << value_int; //调用两次是为了防止string类型和int类型的输出使读者混淆。
ss << value_int;
string temp_string = "";
cout << temp_string << "\t";
ss >> temp_string;
cout << temp_string << endl;
ss.clear(); //int<--->bool之间的转换
ss << value_bool;
bool temp_bool = false;
cout << temp_bool << "\t";
ss >> temp_bool;
cout << temp_bool << endl;
}
#include <string>
#include <sstream>
using namespace std;
int main(int argc,char** argv){
int value_int = 111;
double value_double = 1.11;
string value_string = "111";
bool value_bool = true;
stringstream ss;
ss.clear(); //int<--->double之间的转换
ss << value_int;
double temp_double = 0.00;
cout << temp_double << "\t";
ss >> temp_double;
cout << temp_double << endl;;
ss.clear(); //int<--->string之间的转换
ss << value_int; //调用两次是为了防止string类型和int类型的输出使读者混淆。
ss << value_int;
string temp_string = "";
cout << temp_string << "\t";
ss >> temp_string;
cout << temp_string << endl;
ss.clear(); //int<--->bool之间的转换
ss << value_bool;
bool temp_bool = false;
cout << temp_bool << "\t";
ss >> temp_bool;
cout << temp_bool << endl;
}
相关文章推荐
- C++ int转string(stringstream可转更多类型)
- c++中的istringstream\ostringstream\stringstream
- C++ stringstream介绍,使用方法与例子
- 【未完待续.....】C++字符串流 istringstream 和 ostringstream 的用法
- C++ stringstream介绍,使用方法与例子
- c++ fstream + string 处理大数据
- C++ stringstream的小结
- c++ stringstream的使用
- C++ gdb stringstream问题
- C++ stringstream 简化数据类型转换
- C++ stringstream的使用 类型转换以及字符分离(功能类似split)
- 【stanford C++】字符串(String)与流(Stream)
- C++ stringstream 用法
- C++ stringstream介绍,使用方法与例子
- c++ fstream + string 处理大数据(与c 的fread)
- c++ stringstream(老好用了)
- c++ stringstream
- c++ stringstream 的clear()清空误区
- C++ stringstream的用法|c++ 字符串流 sstream(常用于格式转换)
- [C++]字符串流 istringstream 和 ostringstream 的用法