c++一些转换操作

来源:互联网 发布:中国城市化进程数据 编辑:程序博客网 时间:2024/06/03 09:33

c++string输出到txt

参考http://blog.csdn.net/hobbit1988/article/details/7983364

头文件:

<iostream> <fstream><sstream>  <vector>

代码:

vector<string> linevec;

for(int i=0;i<syt_index;i++)
{
linevec.push_back();
}
ofstream ofile("D:\\hardd.txt",ofstream::out);
for(vector<string>::iterator cnt=linevec.begin(); cnt!=linevec.end(); ++cnt)
ofile<<(*cnt)<<endl;

ofile.close();


c++string与int之间的转换

参考http://www.cnblogs.com/nzbbody/p/3504199.html

头文件

#include <sstream>

#include  <fstream>

代码

int n = 10320;
    std::stringstream ss;
    std::string str;
    ss<<n;
    ss>>str;
    str += "fudsck";
    cout << str<< endl;


    string temp  ="123123";
    str = temp;
    int x = atoi(str.c_str());
    cout << x<< endl;

0 0
原创粉丝点击