标题:字符串输入输出问题
取消只看楼主
xyaofeng
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2015-7-8
结帖率:50%
已结贴  问题点数:10 回复次数:0 
字符串输入输出问题
程序代码:
#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:新人,没有多少积分



[ 本帖最后由 xyaofeng 于 2015-7-8 17:14 编辑 ]
搜索更多相关主题的帖子: 字符串 
2015-07-08 17:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-455218-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.187819 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved