// primerp81_322.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<string>
#include<iostream>
/*using std::string;
using std::cin;
using std::cout;
using std::endl;*/
using namespace std;//与上面注释的等价
int main()
{
//3.2 3.3 getling与cin
/*
string line;
//while (getline(cin, line))//一次读一句,可以包含空格
//while(cin>>line)//不可以包含空格
cin >>line;//如果没有while 则只输出除空格外的第一个单词
cout << line << endl;
*/
/* //3.4 比较是否相等
string line1, line2;
cin >> line1 >> line2;
if (line1 != line2)
{
if (line1 >= line2)
cout << line1;
else
{
cout << line2;
}
}
else
cout << "equal" << endl;
*/
/* //长度相等3.4
string line1, line2;
cin >> line1 >> line2;
auto len1, len2;//用auto判断是啥类型
len1 = line1.size();
len2 = line2.size();
if (len1 != len2)
{
if (len1 >= len2)
cout << len1;
else
{
cout << len2;
}
}
else
cout << "equal" << endl;
*/
/* //3.5输入多个字符串 连接
string line1, line2;//如何让文件结束?????
char choose = 'y';//人为引入标记判断文件是否结束
cout << "please input the first word" << endl;
while(cin >> line2)
{
cout << "y or n?" << endl;
cin >> choose;
if (choose == 'y'||choose=='Y')//把可能性都包含进
{
cout << "continue:" << endl;
//cin >> line2; 前面里面的while(cin>>line1)就是不断在输入了,所以这里不要这一句,否则,程序卡在这里
line1 = line1 + line2;
}
else
break;
}
line1 = line1 + line2;//若if里面的这一句放在if之前,最后就不用加这句了,但现在还少了一次加法,所以需要这一句
cout << line1 << endl;//依旧是在while跳出后输入结果
*/
//3.5用空格把输入的多个字符串分隔来开
string line1, line2;
char choose = 'y';
cout << "please input the first word" << endl;
while (cin >> line2)
{
if (line1.size() == 0)
{
line1 = line1 + line2;
}
else
line1 = line1 + ' ' + line2;
cout << "y or n?" << endl;
cin >> choose;
if (choose == 'y' || choose == 'Y')
{
cout << "continue" << endl;//上述对字符串的处理还是放在上面比较好,不然少一次,对于复杂的处理在while之后再加是相当麻烦的
}
else break;
}
cout << line1 << endl;
system("pause");
return 0;
}
//
#include "stdafx.h"
#include<string>
#include<iostream>
/*using std::string;
using std::cin;
using std::cout;
using std::endl;*/
using namespace std;//与上面注释的等价
int main()
{
//3.2 3.3 getling与cin
/*
string line;
//while (getline(cin, line))//一次读一句,可以包含空格
//while(cin>>line)//不可以包含空格
cin >>line;//如果没有while 则只输出除空格外的第一个单词
cout << line << endl;
*/
/* //3.4 比较是否相等
string line1, line2;
cin >> line1 >> line2;
if (line1 != line2)
{
if (line1 >= line2)
cout << line1;
else
{
cout << line2;
}
}
else
cout << "equal" << endl;
*/
/* //长度相等3.4
string line1, line2;
cin >> line1 >> line2;
auto len1, len2;//用auto判断是啥类型
len1 = line1.size();
len2 = line2.size();
if (len1 != len2)
{
if (len1 >= len2)
cout << len1;
else
{
cout << len2;
}
}
else
cout << "equal" << endl;
*/
/* //3.5输入多个字符串 连接
string line1, line2;//如何让文件结束?????
char choose = 'y';//人为引入标记判断文件是否结束
cout << "please input the first word" << endl;
while(cin >> line2)
{
cout << "y or n?" << endl;
cin >> choose;
if (choose == 'y'||choose=='Y')//把可能性都包含进
{
cout << "continue:" << endl;
//cin >> line2; 前面里面的while(cin>>line1)就是不断在输入了,所以这里不要这一句,否则,程序卡在这里
line1 = line1 + line2;
}
else
break;
}
line1 = line1 + line2;//若if里面的这一句放在if之前,最后就不用加这句了,但现在还少了一次加法,所以需要这一句
cout << line1 << endl;//依旧是在while跳出后输入结果
*/
//3.5用空格把输入的多个字符串分隔来开
string line1, line2;
char choose = 'y';
cout << "please input the first word" << endl;
while (cin >> line2)
{
if (line1.size() == 0)
{
line1 = line1 + line2;
}
else
line1 = line1 + ' ' + line2;
cout << "y or n?" << endl;
cin >> choose;
if (choose == 'y' || choose == 'Y')
{
cout << "continue" << endl;//上述对字符串的处理还是放在上面比较好,不然少一次,对于复杂的处理在while之后再加是相当麻烦的
}
else break;
}
cout << line1 << endl;
system("pause");
return 0;
}