#include<string>
#include<iostream>
#include<cctype>
using namespace std;
//performs string operations
void string_get()
{
string text;
cout<<" enter string "<<endl;
getline(cin,text);
string::size_type position=text.find(' ');
if(position!=string::npos)
{
if(text.find(' ',position+1)!=string::npos)
{
cout<<" contains at least two spaces "<<endl;
}
else
{
cout<<" contains less then two spaces "<<endl;
}
}
else
{
cout<<" no spaces "<<endl;
}
}
int main()
{
string_get();
return 0;
}
私はこのコードを実行し、いくつかの文字列を入力すると、それが正常に動作しますが、そのような疑問があるが、つまりそれはと言っている与えられた文字列にスペースがある場合は、テストコードの短い断片でありますこのコードにバグがあり、それを修正するよう依頼されていますが、どのバグがここにあるのかわかりませんでしたか?文字列がNULLか文字列にスペースが含まれていませんか?
stooooooooooooooooop downvoting –
なぜダウン投票? – Nick
リンチ暴徒(または羊の束)のように聞こえる – Nick