使用C++的string类,编写程序将5个字符串按逆转后的顺序显示出来。
使用C++的string类,编写程序将5个字符串按逆转后的顺序显示出来。例如,逆转前的5个字符串是:GermanyJapanAmericaBritainFrance,逆转...
使用C++的string类,编写程序将5个字符串按逆转后的顺序显示出来。例如,逆转前的5个字符串是:Germany Japan America Britain France,逆转后的顺序输出字符串是:France Britain America Japan Germany
展开
2个回答
展开全部
#include <iostream>
#include <string>
using namespace std;
void main()
{
string str[5];
cout<<"请分别输入5个字符串:"<<endl;
cout<<"1: ";
cin>>str[0];
cout<<endl<<"2: ";
cin>>str[1];
cout<<endl<<"3: ";
cin>>str[2];
cout<<endl<<"4: ";
cin>>str[3];
cout<<endl<<"5: ";
cin>>str[4];
cout<<endl<<"输入的5个字符串分别是:"<<endl;
cout<<str[0]<<" "<<str[1]<<" "<<str[2]<<" "<<str[3]<<" "<<str[4]<<endl;
cout<<"逆转后的顺序为:"<<endl;
cout<<str[4]<<" "<<str[3]<<" "<<str[2]<<" "<<str[1]<<" "<<str[0]<<endl;
}
#include <string>
using namespace std;
void main()
{
string str[5];
cout<<"请分别输入5个字符串:"<<endl;
cout<<"1: ";
cin>>str[0];
cout<<endl<<"2: ";
cin>>str[1];
cout<<endl<<"3: ";
cin>>str[2];
cout<<endl<<"4: ";
cin>>str[3];
cout<<endl<<"5: ";
cin>>str[4];
cout<<endl<<"输入的5个字符串分别是:"<<endl;
cout<<str[0]<<" "<<str[1]<<" "<<str[2]<<" "<<str[3]<<" "<<str[4]<<endl;
cout<<"逆转后的顺序为:"<<endl;
cout<<str[4]<<" "<<str[3]<<" "<<str[2]<<" "<<str[1]<<" "<<str[0]<<endl;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询