六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 78|回复: 0

继续C++输入的学习。

[复制链接]

升级  4.67%

15

主题

15

主题

15

主题

秀才

Rank: 2

积分
57
 楼主| 发表于 2013-1-27 04:47:16 | 显示全部楼层 |阅读模式
      有关C++的输入cin,getline,get, 大家是不是都明白了?这个东西看其来是不难,但是你如果不是很留心,马上就会出错的。呵呵!
      现在给大家一个C++程序。^_^!大家先看看CPP程序,想一下程序运行结果,然后在C++编译器里编译一下。看看你想的和你运行的结果是不是一样??
     
// strtype4.cpp -- line input#include <iostream>#include <string>               // make string class available#include <cstring>              // C-style string libraryint main(){    using namespace std;    char charr[20];     string str;    cout << "Length of string in charr before input: "          << strlen(charr) << endl;    cout << "Length of string in str before input: "         << str.size() << endl;    cout << "Enter a line of text:\n";    cin.getline(charr, 20);     // indicate maximum length    cout << "You entered: " << charr << endl;    cout << "Enter another line of text:\n";    getline(cin, str);          // cin now an argument; no length specifier    cout << "You entered: " << str << endl;    cout << "Length of string in charr after input: "          << strlen(charr) << endl;    cout << "Length of string in str after input: "         << str.size() << endl;    return 0; } 
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表