分别用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;
}
哪里不对,麻烦指出.谢谢