必须有一些明显的东西我没有意识到这个关于 C++ 的东西。
load(string & filename){
string command;
char delimiter = '/';
size_t delimiterPos = filename.rfind(delimiter);
string directory = string(filename.c_str(),delimiterPos);
command = "import path ";
//want to add directory to end of command
string temp = command + "hello!"; // This works
command.append(directory); //This works!
command += directory; //This seg faults!
...
}
在 GDB 中,当我在函数开头“打印”文件名时,我得到: (const string &) @0x9505f08: {static npos = 4294967295, _M_dataplus = {> = {<__gnu_cxx::new_allocator> = {}, }, _M_p = 0x950a8e4 "../config/pythonFile.py"}}
到底是什么,文件名的格式如何不正确,这样 .append() 有效而 += 无效?!C++ 中的重载函数 += 有什么奇怪的吗?
g++ 版本 3.4.6