六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 96|回复: 0

解决那个让高级C++程序员都会出错的问题。

[复制链接]

升级  4.67%

15

主题

15

主题

15

主题

秀才

Rank: 2

积分
57
 楼主| 发表于 2013-2-5 01:26:23 | 显示全部楼层 |阅读模式
      上次给大家说了一个题目,呵呵。没有给出大家解决的问题。
      现在给出大家解决方法。
     
// instr2.cpp -- reading more than one word with getline#include <iostream>int main(){    using namespace std;    const int ArSize = 20;    char name[ArSize];    char dessert[ArSize];    cout << "Enter your name:\n";    cin.getline(name, ArSize);  // reads through newline    cout << "Enter your favorite dessert:\n";    cin.getline(dessert, ArSize);    cout << "I have some delicious " << dessert;    cout << " for you, " << name << ".\n";    return 0; } 
     大家可以看看输出结果。
     对比一下上次的代码的输出结果。
  
// instr1.cpp -- reading more than one string#include <iostream>int main(){    using namespace std;    const int ArSize = 20;    char name[ArSize];    char dessert[ArSize];    cout << "Enter your name:\n";    cin >> name;    cout << "Enter your favorite dessert:\n";    cin >> dessert;    cout << "I have some delicious " << dessert;    cout << " for you, " << name << ".\n";    return 0; } 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

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