不显示你需要的东西,一般我不知道怎么写(
#include <iostream>
#include <string>
using namespace std;
int main()
{
setlocale(LC_ALL, "rus");
string str;
cin >> str;
cout << "Символы: ";
for (int i = 0; i < str.length(); i++) {
while (str[i]){
if (ispunct(str[i])){
cout << "str[" << i << "] = " << str[i] << endl;
}
i++;
}
}
}
你认为什么是分割标记?
ispunct()
只检查标点符号。如果您还想检查空格和制表符,请使用isspace()
. 另外,如果你的字符串有空格,那么普通的cin
就行不通了。需要使用getline()
。并且仍然不清楚为什么while
当你在里面遇到所需的字符for
并且已经通过这个循环完成了该行的其余部分时,你开始一个循环,尽管所有这些都可以使用来完成for
: