![]() |
#2
诸葛欧阳2015-07-08 17:14
|

#include<iostream>
#include<string>
using namespace std;
int main()
{
string str1 ;
str1[0] = 'a';
cout << str1<<endl;
return 0;
}
//什么都没有输出
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str1;
cin >> str1;
str1[0] = 'a';
cout << str1 << endl;
return 0;
}
//当输入cde,输出ade
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str1 = { '\0' };
str1[0] = 'a';
str1[1] = 'b';
cout << str1 << endl;
return 0;
}
//输出a
上面三段小程序的中的第一个程序的a和第三个程序的b没有赋值成功,是什么原因?
PS:新人,没有多少积分
#include<string>
using namespace std;
int main()
{
string str1 ;
str1[0] = 'a';
cout << str1<<endl;
return 0;
}
//什么都没有输出
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str1;
cin >> str1;
str1[0] = 'a';
cout << str1 << endl;
return 0;
}
//当输入cde,输出ade
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str1 = { '\0' };
str1[0] = 'a';
str1[1] = 'b';
cout << str1 << endl;
return 0;
}
//输出a
上面三段小程序的中的第一个程序的a和第三个程序的b没有赋值成功,是什么原因?
PS:新人,没有多少积分
[ 本帖最后由 xyaofeng 于 2015-7-8 17:14 编辑 ]