相关疑难解决方法(0)

cd中的std :: string vs string

可能重复:
为什么'using namespace std;' 在C++中被认为是一种不好的做法?
使用std命名空间

我一直在一堆不同的论坛上徘徊,我似乎每次都会看到这种情况.这是一个非常初学的问题.

我通常定义一个程序

#include<string>
using namespace std;

string x;
Run Code Online (Sandbox Code Playgroud)

我看到一堆代码示例将字符串定义为

std::string.
Run Code Online (Sandbox Code Playgroud)

这样做的目的是什么?是好的做法还是有一些功能?

c++ string std

49
推荐指数
3
解决办法
6万
查看次数

C++ Literal String Concatenation

我有一个关于C++中字符串连接的问题.

string str = "ab" + 'c';
cout << str << endl;

char ch = 'c';
string str1 = "ab";
string str2 = str1 + ch;
cout << str2 << endl;
Run Code Online (Sandbox Code Playgroud)

代码产生:

ed before SaveGraphicsState
abc
Run Code Online (Sandbox Code Playgroud)

有人可以解释这一行的处理:string str = "ab" + 'c';

c++ string concatenation

8
推荐指数
1
解决办法
4444
查看次数

标签 统计

c++ ×2

string ×2

concatenation ×1

std ×1