我要把一行带空格的字符串输入到一个文件中
比如 吧 hello world 输入到nu.txt文件中
怎么用getline?
===========================================
下面是附加题(做出来追加分哦~)
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
int main()
{
char buf1[50],buf2[50],ch;
cout<<"请输入一串字符";
cin>>buf1;
ofstream outfile("al.txt");
if(!outfile)
{
cout<<"文件打开失败"<<endl;
return 1;
}
outfile<<buf1<<endl;
outfile.close();
ifstream infile("al.txt");
if(!infile)
{
cout<<"文件打开失败"<<endl;
return 1;
}
while(!infile.eof())
{
infile.get(ch);
if(ch>='a'&&ch<='z')
{
ch=ch-'a'+'A';
}
cout<<ch;
}
ofstream out("a2.txt");
if(!out)
{
cout<<"文件打开失败"<<endl;
return 1;
}
outfile<<buf2<<endl;
out.close();
infile.close();
return 0;
}
要将一行带空格的字符写入a1.txt中,将其读取并且将所有小写字母改成大写,再写入a2.txt
叮当猫咪
红颜莎娜
芜湖不芜
相关分类