1.程序
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int main(){
vector<int> forwrite;
for(int t = 0; t < 10; t++){
forwrite.push_back(t);
}
ofstream OutFile("./myfile.txt");
for(int t =0; t < 10; t++){
char cw = forwrite[t] + '0';
//或者可以用下面这行方法转,当将较大的数转换成字符串时,就可以用这一句了,如果仅转为char可以继续用上面那句
//OutFile<<to_string(t)<<" ";
OutFile<< cw <<" ";
}
OutFile<<"\n";
OutFile.close();
return 0;
}
2.结果
0 1 2 3 4 5 6 7 8 9
版权声明:本文为broliao原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。