说我正在上课:
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) 当字符串构造函数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 []?
我system( `sed -i 's/[ 0-9]+) //' fileName` );在perl脚本中有一行直到完成.但该文件未被编辑.
当我sed -i 's/[ 0-9]+) //' fileName在shell上运行它运行正常并按预期编辑文件.为什么他们会有不同的结果,我该如何解决?