5.17 cin.get(ch) 循环输入输出字符串

程序来源 :C++ primer plus
章 节 :5.5
名 称 :5.17 textin2.cpp
功 能 :循环输入输出字符串
开发时间 :2020-1-9
版 本 :v1.0
运行测试 :通过
C++11支持:执行工具-编译选项 输入
-std=c++11 并打钩

/********************************
 * 程序来源 :C++ primer plus
 * 章    节 :5.5
 * 名    称 :5.17 textin2.cpp
 * 功    能 :循环输入输出字符串
 * 开发时间 :2020-1-9
 * 版    本 :v1.0
 * 运行测试 :通过
 * C++11支持:执行工具-编译选项 输入
 *            -std=c++11 并打钩
 *******************************/
#include 

using namespace std;

int main() {
    char ch;
    int count = 0;
    cout <<"Enter chararcters;Enter '#' to quit:\n";
    cin.get(ch);     //can read space , enter 
    while(ch != '#') {
        cout << ch;
        count ++;
        cin.get(ch);    //not cin >> ch
    } 
    cout << endl << count << " Charactors read.\n";
    return 0;
}

运行结果:

  
/**********************************
 *            程序输出            *
 **********************************
 Enter chararcters;Enter '#' to quit:
my name is sunset
my name is sunset
my love is c#
my love is c
30 Charactors read.

--------------------------------
Process exited after 22.68 seconds with return value 0
请按任意键继续. . .
**********************************/

声明:本代例子码源自教材非原创,是笔者的学习笔记,仅用于学习交流。

你可能感兴趣的:(5.17 cin.get(ch) 循环输入输出字符串)