C++里 string类怎么感觉有点小bug,吧友可以帮忙看看么?
c++吧
全部回复
仅看楼主
level 3
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
void main()
{ fstream file("surname.txt",ios::in|ios::out);
string temp;
file>>temp;
string a;
cout<<temp[0]<<temp[1]<<endl; //"surname.txt"文件中前两个字符连起来是汉字"罗"
a=temp[0]+temp[1];
cout<<"here:"<<a<<endl;
//可以输出第一行的一个字"罗",但是a却不能输出,出来只是空白,请问是怎么回事呢?
}
2015年09月22日 06点09分 1
level 3
但是如果把a定义为 char a[3],然后依次赋值,最后cout<<a;就可以输出"罗"了
2015年09月22日 06点09分 2
level 13
string只适合用于单字节字符集,这大概属于缺失特性……不过如果指望“1个字符+1个字符=1个字符”的话,不妨重新考虑一下,1+1等于多少
2015年09月22日 07点09分 3
那我这个应该怎么改呢?
2015年09月22日 11点09分
强行#define char wchar_t 反正都敢void main了也不在乎了。
2015年09月22日 11点09分
回复
�ä��ϵ�
: 不能void main 么? 我编C的时候都是VOID MAIN的.....
2015年09月22日 11点09分
level 9
char的operator+都能返回string了
2015年09月22日 11点09分 4
level 15
string和char是两个概念
2015年09月23日 12点09分 5
level 5
楼主是从别的语言转来的吧
2015年09月23日 14点09分 7
level 8
用operator+=
2015年09月23日 15点09分 8
1