   Simple Error Help
  Does anyone know how I can fix this?int Length = GetWindowTextLength(nWind);wchar_t Buffer[Length];GetWindowText(nWind, Buffer, sizeof(Buffer)/sizeof(Buffer[0]));I keep getting these errors:1>c:\users\matt\documents\visual studio 2008\projects\ustest\ustest\main.cpp(13) : error C2057: expected constant expression1>c:\users\matt\documents\visual studio 2008\projects\ustest\ustest\main.cpp(13) : error C2466: cannot allocate an array of constant size 01>c:\users\matt\documents\visual studio 2008\projects\ustest\ustest\main.cpp(13) : error C2133: 'Buffer' : unknown size1>c:\users\matt\documents\visual studio 2008\projects\ustest\ustest\main.cpp(14) : error C2070: 'wchar_t []': illegal sizeof operandThanks in advance!   
  The array size must be a compile time constant and cannot be evaluated at run time. Use a dynamic vector instead.int Length = GetWindowTextLength(nWind);std::vector<wchar_t> Buffer(Length);GetWindowText(nWind, &Buffer[0], Length);;  Now this error:1>c:\users\matt\documents\visual studio 2008\projects\ustest\ustest\main.cpp(17) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)With this code:std::wofstream File;File.open("Test.lua");File << Buffer;File.close();;int Length = GetWindowTextLength(nWind);wchar_t Buffer = new wchar_t[Length];GetWindowText(nWind, Buffer, Length);Remember to delete or use a smart_ptr.Or using Brother Bob's example you might useFile << &Buffer[0];;  I got it to work:int Length = GetWindowTextLength(nWind);wchar_t *Buffer = new wchar_t[Length+1];GetWindowText(nWind, Buffer, Length+1);std::wofstream File;File.open("Test.lua");File << Buffer;File.close();delete Buffer;Any suggestions for anything I am doing sloppy?  Thanks!   ;  You're using the wrong delete operator. It's delete [] Buffer;   ;  Stick with Bob's vector code if you can.  Otherwise, remember to use delete [] Buffer (as you've allocated an array, not just a single object).   ;Quote:Any suggestions for anything I am doing sloppy?  Thanks!Here's a slightly revised version of your code (not compiled or tested):std::vector<wchar_t> buffer(GetWindowTextLength(nWind) + 1);GetWindowText(nWind, &buffer.front(), buffer.size());std::wofstream file("Test.lua");file << &buffer.front();The main differences are:1. Use of std::vector makes the code (more) exception safe, and obviates the need for manual cleanup and for 'remembering' the length of the buffer.2. Opening the file using the wofstream constructor tightens the code up a bit.3. The (most likely) unnecessary call to close() has been removed (I'm assuming that this code resides in a function or some other scoped block, and that the file object will therefore go out of scope soon after this code finishes executing).There are probably some opportunities for error-checking there as well, but I didn't address them in my example.[Edit: Some of these improvements were already suggested in earlier posts.]   ;  Thanks, and it did work.   