[英]C++ Winapi. Read first line from a file, displaying in a textbox
I have recently begun to experiment with winapi in C++. 我最近开始在C ++中尝试使用winapi。 Coming along nicely so far.
到目前为止进展顺利。
I do however having a problem with finding a way to read the first line of a file, and displaying it in a textbox. 但是,我确实在寻找一种方法来读取文件的第一行并将其显示在文本框中时遇到问题。
After some google searching it seems that some people suggest using winapis functions for this, while other say that using fstream is simpler. 在一些Google搜索之后,似乎有人建议为此使用winapis函数,而其他人则说使用fstream更简单。 I did go the fstream way but i run in to some trouble, probably nothing very difficult but, i cannot find an answer for it!
我确实采用了fstream的方式,但是遇到了一些麻烦,也许没有什么困难,但是,我找不到答案!
this is my code: 这是我的代码:
string line;
ifstream filen ("tid.txt");
if (filen.is_open())
{
getline (filen,line);
cout << line << endl;
filen.close();
}
SetDlgItemText(hwnd, IDC_MAIN_EDIT, line);
This give me this problem from the compiler: 这给我这个来自编译器的问题:
Cannot convert `std::string' to `const CHAR*'
Need somekind of conversion here, but dont know what. 这里需要某种转换,但不知道是什么。
What do you think? 你怎么看?
尝试这个:
SetDlgItemText(hwnd, IDC_MAIN_EDIT, line.c_str());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.