C++で最初のChar配列に10文字以上cin.getline()で入力した場合次のcin.get()がスキップされます。
cin.clear(), cin.ignoreを使ってみましたがうまくいきませんでした。
ググってみたのですが似たような例があるものの試してみてもうまくいきません。
どのようにすれば解決できるでしょうか?
C++
1using namespace std; 2 3int main(){ 4 5 const int SIZE_STATE = 11; // size of state 6 char state[SIZE_STATE]; // need 11 because should care about null (EOS) 7 cout << "Input: "; 8 cin.getline(state, SIZE_STATE); 9 cout << state << endl; 10 11 const int SIZE_CHAR = 11; 12 char charArray[SIZE_CHAR]; // need 11 because should care about null (EOS) 13 cout << "Input: "; 14 cin.get(charArray, SIZE_CHAR, '.'); 15 cout << charArray << endl; 16}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/19 01:57