<分区>
在情况 1 中,当我像这样初始化一个字符串时,输出为空白:
#include <iostream>
#include<string>
using namespace std;
//CODE 1
int main()
{
string s="hello" + 'c';
cout<<s<<endl;
return 0;
}
但是当我这样写时它工作正常:
#include <iostream>
#include<string>
using namespace std;
//CODE 2
int main()
{
string s="hello";
char k='c';
s+=k;
cout<<s<<endl;
return 0;
}
现在我很困惑,因为在另一个关于堆栈溢出的问题中,它说当使用 namespace std 时,string 和 std::string 之间没有区别,这些答案是说 -> string 和 std::string 之间没有功能差异,因为它们是同一类型 std::string vs string in c++ 而为这个问题提供的答案却指出了不同点:
编译器是 g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)