Hi
I need to cast string type variable to LPCTSTR type. How to achieve this. I am inserting my code for yours help.

ifstream file(filename);
if (file)
{
char ch='\n' ;
do
{
file.getline(line, SIZE);
tmp =static_cast<string>(line); 
vector <string> array; 
string token; // token decleared string type 
istringstream iss(tmp);
for (int i=1; i<6;)
{ while ( getline(iss, token, ',') )
{
array.push_back(token);
v_List.SetItemText(nItem, i, token); 
/* token is of string type so compiler gives error that can't convert 'std::string' to 'LPCTSTR' */
i++;
}
}//cin.get();
}while(ch!='\n'); //(ch=EOF)

}

Any help please ..........

Try this line

v_List.SetItemText(nItem, i, token.c_str());

This is not a cast, but you will be able to access the C style characters in token.

Try this line

v_List.SetItemText(nItem, i, token.c_str());

This is not a cast, but you will be able to access the C style characters in token.

Yes, it working fine for me! Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.