64,636
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
int main()
{
int source;
string str;
cout<<"请选择是直接从屏幕输入还是从文件输入: 1 屏幕输入 2 文件导入"<<endl;
while(getline(cin,str))
{
if(str!="1" && str!="2")
{
cout<<"输入错误,请重新输入"<<endl;
continue;
}
else
{
source=str[0]-'0';
break;
}
}
cout<<"source:"<<source<<endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
cout<<"请将资源文件保存在ziyuanyuanshi.in中,然后按回车确认!"<<endl;
while(getline(cin,str) && str.size()!=0)
{
//因为getline将回车符转化成'\0'存储,所以直接输入回车字符串为空
}
return 0;
}