How could i pass the value of vector string to the win32 Function SetWindowText in C++.
so far this is my cod开发者_StackOverflow社区e for that:
vector <string> filelist;
string path;
path = Text;
filelist = GetPath(path);
SetWindowText(EditShow,filelist);
You could concatenate them all into one string and pass that as a c-string:
#include <sstream> // for std::stringstream
#include <algorithm> // for std::copy
#include <iterator> // for std::ostream_iterator
std::stringstream buffer;
std::copy(filelist.begin(), filelist.end(),
std::ostream_iterator<std::string>(buffer, "\n");
SetWindowText(EditShow,buffer.str().c_str());
First off, you seem to be trying to insert a list of strings into SetWindowText.
since each window can only have one title, SetWindowText cannot process a list. Instead, you should retrieve a single string from the list, and use it as a parameter to SetWindowText
string windowText = filelist[0];
The documentation from SetWindowText reveals that the function expects a LPCTSTR lpString
.
Since all we have right now is a string
, we have to use
LPCTSTR title = windowText.c_str();
It is possible that this line will not compile with the following error message :
cannot convert from 'const char *' to 'LPCTSTR'
You will have to change the default character set in your project. Here is how you do it
Finally you can call
SetWindowText(EditShow,title);
精彩评论