我只是想将字符串转换为char(更准确地说是char *),但无缘无故,如果我在codeBlocks或项目中运行代码,则会得到不同的输出。因此,在codeBlocks上,我运行以下命令:
#include <iostream>
#include <string>
using namespace std;
int main()
{
std::string stlstring = "abc";
std::cout << stlstring << std::endl;
char* writable = new char[stlstring.size() + 1];
std::copy(stlstring.begin(), stlstring.end(), writable);
writable[stlstring.size()] = '\n';
std::cout << writable ;
}
Run Code Online (Sandbox Code Playgroud)
在我的项目中,我在事件处理程序中运行相同的行:
void RePROGUIUser::applyOptions(wxCommandEvent& event) {
std::string stlstring = "abc";
std::cout << stlstring << std::endl;
char* writable = new char[stlstring.size() + 1];
std::copy(stlstring.begin(), stlstring.end(), writable);
writable[stlstring.size()] = '\n';
std::cout << writable;
}
Run Code Online (Sandbox Code Playgroud)
因此,我必须在GUI上按一个按钮以使其实现,但实际上它不应更改任何内容(我对将wxWidget标记放在此处表示怀疑)。
有人知道吗?