I want to read text from a file and display it in the win32 Edit(ReadOnly). I am having problems converting from std::string to w_char*/LPWCSTR. The program reads the text from the textfile into a vector<std::string> object. I want to display each item in the vector on a new line inside the Edit. The displayed text is not what was read from the file though, e.g.
The original string: "Last year in august a bear was spotted in the norwood woods...",
the displayed text: "M1TELBbJM7StfoRRtfoAAtfoA8AtfoJJtfoJJtfoU9UtfoJJtfoAAtfoHWbMpsaA"
Code that recieves the vector and displays it in the edit:
//method used to append text to Edit
void appendTextToEdit( HWND Edit, LPCWSTR newText ){
int TextLen = SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0);
SendMessage(hEdit, EM_SETSEL, (WPARAM)TextLen, (LPARAM)TextLen);
SendMessage(hEdit, EM_REPLACESEL, FALSE, (LPARAM)newText);
}
void display_data(){ //function for displaying lines
data = new vector<string>(); //vector holding the lines read from the file
*data = *file->read_from_file(); //header file method (below)
//loop for displaying the data on individual lines in the edit
for(unsigned i = 0; i < data->size(); i++){
wstring stemp = wstring(data->at(i).begin(), data->at(i).end());
LPCWSTR line = stemp.c_str();
appendTextToEdit(hEdit, /*(LPCWSTR)*/ line);
}
delete data;
delete file;
}
In the header file: "FileMag.h", the method for reading from the file:
std::vector<std::string>* read_from_file(){ //method for reading from file
if(!read_in->fail()){
std::string line = "";
point = new std::vector<std::string>(); //memory deleted in deconstructor
while(!read_in->eof()){
*read_in >> line;
point->push_back(line);
}
read_in->close(); //close file
return point;
}else{
file_ex er; //custom error class extending std::exception
er.set_msg("Could not access file"); //set error message to display
throw er;
}
return NULL;
}