33,311
社区成员
发帖
与我相关
我的任务
分享
//给个例子,自己改成类就行了
int main(int argc, char *argv[])
{
ofstream out("1.txt");
if(!out){
cout << "open file failed!" << endl;
return 1;
}
out << setiosflags(ios::right) << setw(20) << "test" << endl;
out.close();
ifstream in("1.txt");
if(!in){
cout << "open file failed!" << endl;
return 1;
}
char str[100];
in >> str;
cout << str << endl;
return 0;
}