Accessing TCHAR[] array from an vector.
-
Hi, In my application, I store an array of TCHAR[MAX_PATH] strings into an vector as indicated by the code snippet below.
//in the .h file
#include <vector>
typedef std::vector<std::basic_string<TCHAR>> StringVector;//In the .cpp file
BOOL CMyApp::AddStringToVector()
{
StringVector vect;vect.push\_back(\_T("One")); vect.push\_back(\_T("two")); vect.push\_back(\_T("three")); //later on try accessing the vector element. TCHAR szResult\[MAX\_PATH\]={0}; \_tcscpy(szResult, vect\[1\]);
}
I am able to add all the string. But accessing the stored string from the vector is the problem. _tcscpy(szResult, vect[1]); gives an compilation error Error 11 error C2664: 'wcscpy' : cannot convert parameter 2 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'const wchar_t *' I think this error is caused because the TCHAR that is stored in the vector as std::basic_string<_Elem,_Traits,_Ax> and that the compiler is not able to convert it to an TCHAR[MAX_PATH]. How do I go about accessing the TCHAR elements in the vector? Please help.
-
Hi, In my application, I store an array of TCHAR[MAX_PATH] strings into an vector as indicated by the code snippet below.
//in the .h file
#include <vector>
typedef std::vector<std::basic_string<TCHAR>> StringVector;//In the .cpp file
BOOL CMyApp::AddStringToVector()
{
StringVector vect;vect.push\_back(\_T("One")); vect.push\_back(\_T("two")); vect.push\_back(\_T("three")); //later on try accessing the vector element. TCHAR szResult\[MAX\_PATH\]={0}; \_tcscpy(szResult, vect\[1\]);
}
I am able to add all the string. But accessing the stored string from the vector is the problem. _tcscpy(szResult, vect[1]); gives an compilation error Error 11 error C2664: 'wcscpy' : cannot convert parameter 2 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'const wchar_t *' I think this error is caused because the TCHAR that is stored in the vector as std::basic_string<_Elem,_Traits,_Ax> and that the compiler is not able to convert it to an TCHAR[MAX_PATH]. How do I go about accessing the TCHAR elements in the vector? Please help.
Got the solution. I should be using to access the TCHAR stored in the vector as given below.
_tcscpy(szResult, vect[1].c_str());