#include <string>
#include <iostream>
void main()
{
using std::string;
using std::cin;
using std::cout;
using std::endl;
//获取一行字符串,并且只显示超过指定长度的行
string line;
//while (getline(cin, line))
//{
//if (line.size() > 2)
//{
//cout << line << endl;
//}
//}
////每次读入一个词
//string str;
//while (cin >> str)
//{
//cout << str << endl;
//}
//读入多个字符串然后连接成大字符串,并用空格分开
string str;
while (getline(cin,str))
{
line += str + " ";
cout << line << endl;
}
}
读入一个包含标点符号的字符串,将标点符号去除后输出字符串的剩余部分
#include <string>
#include <iostream>
void main()
{
using std::string;
using std::cin;
using std::cout;
using std::endl;
//读入一个包含标点符号的字符串,将标点符号去除后输出字符串的剩余部分
//1、方法一
string str2 = "Hello,Word!!!";
string result;
for (auto &c : str2)
{
if (!ispunct(c))
result += c;
}
cout << result << endl;
//2、方法二
string str3("Hello,Word!!!#@jdc");
int num = str3.size();
for (int i = 0; i<num; i++)
{
if (!ispunct(str3[i]))
cout << str3[i];
}
}