-1
CodeBlocksのプログラムの文字列出力をテストしています。ここでは、コードは次のとおりです。それは盗聴されているかのように間違った順序で「入力」スペースとcoutの文字列でdelimiteredされているかのようCodeBlocks文字列の出力を区切り
#include <iostream>
#include <string>
using namespace std;
int main(){
string entry = "";
while(entry!="x"){
cout<<"Enter: ";
cin>>entry;
cout<<entry.substr(0,1)<<endl;
}
return 0;
}
しかし、結果を出力します。どのような理由があり、どのように私はこの状況を解決することができますか?
Output:
Enter: P q r
P
Enter: q
Enter: r
Enter:
'' >>演算子は、空白で区切られたものを抽出します。良い本[ここ](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)のリストがあります。 – molbdnilo
これは、ストリーム入力が正常に動作する方法です。おそらく 'getline'をstd :: stringに代わりたいと思うでしょう。 – Eljay