Search code examples
c++winapifstream

C++ Winapi. Read first line from a file, displaying in a textbox


I have recently begun to experiment with winapi in C++. 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. 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!

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?


Solution

  • Try this:

    SetDlgItemText(hwnd, IDC_MAIN_EDIT, line.c_str());