   C++ (VS 2008) Question - Arrays
  Hi,I'm trying to create a method that takes in a std::string and converts it character by character into an array of wchar_t.However, I'm running into problems with creating the array. The filename I'm passing in has a length of 17 characters, but the array that gets created (what 'filenamechar' is pointing to) is 24 characters long. I don't understand why this is happening.//START CODE BLOCKint filenameLength = filename.length();cout << filenameLength;    //outputs as expectedwchar_t* filenamechar;filenamechar = new wchar_t[filenameLength];    //Does not create the right size!for (unsigned int i = 0; i < filename.length(); i++)filenamechar = filename;//END CODE BLOCKThanks for the help!
  How do you know it's not creating the right size? You're not including the '\0' terminator in your buffer for one thing.Also, the C++ way of doing what you're doing is basically the code provided by Fruny in this thread.The main problem with what you're doing is (apart from using a raw wchar_t array) that it doesn't take the current locale into account so it would only work for ASCII characters.   ;  If you're developing for Windows, you could use MultiByteToWideChar().   ;  The standard C library function would be mbstowcs(). The standard C++ library method would be to use the ctype::widen() member function.   