写入文件
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
int main()
{
const char a[50] = "hello world!123456";
ofstream outfile("f1.txt",ios::out);
for(int i=0;i<strlen(a);i++)
{
outfile<<a[i];
}
outfile.close();
return 0;
}
读出文件
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ifstream readfile("f1.txt",ios::in);
string str;
char tmp;
str = "";
int i = 0;
while(readfile>>tmp)
{
str += tmp;
cout<<tmp<<" "<<i<<endl;
i++;
}
cout<<endl<<str<<endl;
readfile.close();
return 0;
}
tmp为指针,结果不变,与C的区别