小编heh*_*301的帖子

在C++中你需要在两个方向上重载operator ==吗?

说我正在上课:

class Foo{
public:
  std:string name;
  /*...*/
}/*end Foo*/
Run Code Online (Sandbox Code Playgroud)

我提供了一个重载 operator==

bool operator==(const Foo& fooObj, const std::string& strObj) {
    return (fooObj.name == strObj);
}
Run Code Online (Sandbox Code Playgroud)

我是否还需要反向重新实现相同的逻辑?

bool operator==(const std::string& strObj, const Foo& fooObj) {
    return (strObj == fooObj.name);
}
Run Code Online (Sandbox Code Playgroud)

c++ operator-overloading

55
推荐指数
2
解决办法
5280
查看次数

std :: string构造函数如何处理固定大小的char []?

当字符串构造函数char[]中的实际字符序列char[]可能小于最大大小时,它如何处理固定大小?

char foo[64];//can hold up to 64
char* bar = "0123456789"; //Much less than 64 chars, terminated with '\0'
strcpy(foo,bar); //Copy shorter into longer
std::string banz(foo);//Make a large string
Run Code Online (Sandbox Code Playgroud)

在这个例子中,banz对象字符串的大小是基于原始的char*length还是它被复制到的char []?

c++ string c++11

4
推荐指数
1
解决办法
240
查看次数

Perl系统()不能与sed一起使用

system( `sed -i 's/[ 0-9]+) //' fileName` );在perl脚本中有一行直到完成.但该文件未被编辑.
当我sed -i 's/[ 0-9]+) //' fileName在shell上运行它运行正常并按预期编辑文件.为什么他们会有不同的结果,我该如何解决?

regex bash perl sed

-1
推荐指数
1
解决办法
154
查看次数

标签 统计

c++ ×2

bash ×1

c++11 ×1

operator-overloading ×1

perl ×1

regex ×1

sed ×1

string ×1