首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

cin 有关问题求解

2012-04-10 
cin 问题求解下面是我的程序:C/C++ code#include iostreamusing namespace stdint main(){char str1[10

cin 问题求解
下面是我的程序:

C/C++ code
#include <iostream>using namespace std;int main(){    char str1[10];    char str2[10];    int i;    i = 0;    do    {        cout << "\nEnter the first string:\n\n\t";        cin >> str1;        cout << str1;        cout << "\n\nEnter the second string:\n\n\t";        cin.get (str2, 5);        cout << str2 << endl;    }     while (i ++ < 4);    return 0;}

为何不能实现目标,
总是在还没有输入第二个字符串就结束了?

[解决办法]
cout << str1;

cout << "\n\nEnter the second string:\n\n\t";
cin.get();//加上这句
[解决办法]
应该是把输入str1时候的尾部的回车,读入到了str2,所以感觉是还没输入第二个字符串就结束了

热点排行