输入n个字符串,把其中以A开头的的字符串输出,然后我编的就错了。。。
#include<iostream>#include<string>usingnamespacestd;intmain(){constintn=5;stringstr[n...
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int n = 5;
string str[n];
int i, j;
for (i = 0; i < n; i++)
{
cin >> str[i];
}
for (i = 0; i < n; i++)
{
if (str[i] == "A")
cout << str[i] << endl;
}
}
正确代码是这个:
#include <iostream>
#include <string>
using namespace std;
int main()
{ const int n=5;
string str;
for(int i=0;i<n;i++)
{cout<<"please input string:";
cin>>str;
if(str[0]=='A')
cout<<str<<endl;}
return 0;
} 展开
#include <string>
using namespace std;
int main()
{
const int n = 5;
string str[n];
int i, j;
for (i = 0; i < n; i++)
{
cin >> str[i];
}
for (i = 0; i < n; i++)
{
if (str[i] == "A")
cout << str[i] << endl;
}
}
正确代码是这个:
#include <iostream>
#include <string>
using namespace std;
int main()
{ const int n=5;
string str;
for(int i=0;i<n;i++)
{cout<<"please input string:";
cin>>str;
if(str[0]=='A')
cout<<str<<endl;}
return 0;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询