【C&C++】stringstream的一些用法 - 尝试一下新的东西
2008-03-23 14:05
447 查看
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <bitset>
using namespace std;
int main()
...{
/**//*string stream tests*/
/**//*string stream for type conversions*/
// stringstream ss;
// string n="123.456";
// float f=0.0f;
// ss << n; ss >> f; cout << f <<endl;//string stream for type conversions
// f+=333.1458f;
// ss.clear();//多次转换之前必须将流清空
// ss << f; ss >> n; cout << n << endl;
// ss.clear();
// int a=12;stringstream ss;
// string n;
// ss.flags ( ios::hex | ios::showbase );
// ss << a;//输出0X12
// ss >> n;//这样都可以 直接得到16进制的字符串了
// stringstream ss;bitset<16> a(12);string n;
// ss << a; ss >> n;
// cout << n ; 这样就可以转为2进制的字符串了,太强了
/**//*stringstream ss;
ss << "123,456";
string s1;
getline(ss,s1,',');//分割字符串,PARSE
cout << ss.peek();*/
return 0;
}
相关文章推荐
- <C++>istringstream, ostringstream, stringstream的用法
- 整理一下之前工作中记录过的一些东西——sequence:在这里可以解释为"序列"
- C++中引用(&)的用法和应用实例
- C++ 中dynamic_cast<>的用法
- C++里 宏 的一些特别用法(一)
- C++中引用(&)的用法和应用实例
- c++中&的用法
- cin>>,cin.get(),cin.getline()的一些用法
- 关于嵌入式C&&C++的一些编程问题(三)
- 关于嵌入式C&&C++的一些编程问题(四)
- C++中引用(&)的用法和应用实例
- C/C++中*、&用法
- c++中string的一些用法
- C++中引用(&)的用法和应用实例
- 总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法
- C++中引用(&)的用法和应用实例(相当经典!!!)
- C++中引用(&)的用法和应用实例
- C++中引用(&)的用法和应用实例
- C++中引用(&)的用法和应用实例
- C++中static_cast、const_cast、reinterpret_cast的用法举例,附带举例说明强制类型转换时int和int&的区别