【发布时间】:2020-01-25 09:01:44
【问题描述】:
我编写了这段代码,但它没有避免使用标点符号。
string str;
char ch[100];
while(scanf("%s[a-z | A-Z ]",ch)!=EOF)
{
str=ch;
cout<<str<<endl;
}
当我给出以下输入时:
road.sign read:
went home.
它打印以下输出:
road.
sign
read:
went
home.
有没有什么办法可以改进这个代码以打印不带标点的单词?
【问题讨论】:
-
当
c++中有cin/getline时,为什么还要使用scanf? -
cin 有什么方法可以避免输入时出现标点符号吗? getline 将存储一整行,但我需要一个单词来存储。
-
The Regex in scanf goes between % and s like %[^\n]s