我把string类型的字符串的最后一个字符赋值为'\0',然后就不能在末尾增加新的字符串了,有什么办法'\0'去掉吗?但是,类型还是要保持string类型

解决方案 »

  1.   

    you use string type defined in namespace std?
    i make a test,it runs properly.
    #include<iostream>
    #include<string>
    using namespace std;void main()
    {
      string s1="hello\0";
      string s2=" world!";
      string s3 = s1+s2;
      cout<<s3<<endl;
    }
      

  2.   

    this is also right:
    string s1="hello\0";
    string s2=" world!";
    string s3 = s1+s2;
    s1+=" world";
    cout<<s1<<endl;
    ____________________________
    s1:hello world
      

  3.   

    恩,人家stl肯定是找到第一个出现 \0 的地方,就开始连接啦,你加的那个 \0 根本起不到作用.^_^
      

  4.   

    So,LZ did something wrong.
      

  5.   

    So,LZ did something wrong.