qq_33486292
abc罗大侠
2016-03-21 15:51

c++简单问题,代码清晰,求解!

  • c++
  • 新手

分别用char数组和string类型编写代码,使他们输出相同。


#include<iostream>
#include<string>
int main()
{
    using namespace std;
    string name;
    string dessert;

    cout << "Enter your name:\n";
    getline(cin,name);
    cout << "Enter your favorite desseert:\n";
    getline(cin,dessert);
    cout << "I have some delicious " << dessert;
    cout << " for you," << name << ".\n";
    return 0;
}

图片说明

#include<iostream>
#include<string>
int main()
{
    using namespace std;
    const int AirSize = 20;
    char name[AirSize];
    char dessert[AirSize];

    cout << "Enter your name:\n";
    cin.getline(name,AirSize);
    cout << "Enter your favorite desseert:\n";
    cin.getline(dessert,AirSize);
    cout << "I have some delicious " << dessert;
    cout << " for you," << name << ".\n";
    return 0;
}

图片说明
哪里不对,麻烦指出.谢谢

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐