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

请问一个关于CIN的有关问题

2012-05-14 
请教一个关于CIN的问题C/C++ code#include iostreamconst int ArSize10void strcount(const char *str

请教一个关于CIN的问题

C/C++ code
#include <iostream>const int ArSize=10;void strcount(const char *str);int main(){    using namespace std;    char input[ArSize];    char next;    cout<<"Enter a line: \n";    cin.get(input,ArSize);    while(cin)    {        cin.get(next);        while(next!='\n')            cin.get(next);        strcount(input);        cout<<"Enter next line(empty line to quit): \n";        cin.get(input,ArSize);    }    cout<<"Bye\n";    return 0;}void strcount(const char *str){    using namespace std;    static int total=0;    int count =0;    cout<<"\""<<str<<"\"contains";    while(*str++)        count++;    total+=count;    cout<<count<<"characters\n";    cout<<total<<"charaters total\n";}

此段代码中
while(cin)以及 cin.get(next)
请问这2处的cin是如何收到值的,程序执行的时候只是在cin.get(input,ArSize);输入了值

[解决办法]
while(cin)是判断当前的流状态是否处于可用。
cin.get(next),在当前输入缓冲区中读入一个字符到next.
C/C++ code
 cin.get(next);        while(next!='\n')            cin.get(next); 

热点排行