我使用:
std::ifstream t("myfile.txt");
std::string str((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
SendMessage(hwndEdit, WM_SETTEXT, 0, (LPARAM) str);
将 myfile.txt
的内容读入创建的文本框中:
HWND hwndEdit = CreateWindowEx(0, L"EDIT", NULL, WS_CHILD | WS_VISIBLE, ...)
如何解决这个错误?:
main.cpp(34) : error C2440: 'type cast' : cannot convert from 'std::string' to 'LPARAM'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
最佳答案
据我了解 WM_SETTEXT lparam 的文档应该是
A pointer to a null-terminated string that is the window text.
表示c风格的字符串,一个char*变量。您可以尝试将 str.c_str() 传递给 lParam。
关于c++ - 读取文件并将其添加到文本框 : string conversion issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27779067/