title: Converting _TCHAR* to char*
body: <p>I'm trying to get <a href="https://github.com/Itseez/opencv/blob/master/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp" rel="nofollow noreferrer">a simple OpenCV sample</a> working in C++ on Windows and my C++ is more than rusty.</p>
  
  <p><a href="https://github.com/Itseez/opencv/blob/master/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp" rel="nofollow noreferrer">The sample</a> is fairly simple:</p>
  
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;iostream&gt;
  
  using namespace cv;
  using namespace std;
  
  int main( int argc, char** argv )
  {
      if( argc != 2)
      {
          cout &lt;&lt;" Usage: display_image ImageToLoadAndDisplay" &lt;&lt; endl;
          return -1;
      }
      Mat image;
      image = imread(argv[1], IMREAD_COLOR); // Read the file
      if(! image.data )                      // Check for invalid input
      {
          cout &lt;&lt;  "Could not open or find the image" &lt;&lt; std::endl ;
          return -1;
      }
      namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
      imshow( "Display window", image );                // Show our image inside it.
      waitKey(0); // Wait for a keystroke in the window
      return 0;
  }
  </code></pre>
  
  <p>When I make a new simple C++ console application (with ATL) in Visual Studio 2012 I get a different template for <code>main</code>:</p>
  
  <pre><code>int _tmain( int argc, _TCHAR* argv[] )
  </code></pre>
  
  <p>So before I send the filename to OpenCV's <code>imread</code> function I need to convert the <code>_TCHAR*</code> <code>arg[1]</code> to a <code>char*</code>. Using a simple filename, 'opencv-logo.jpg', from the memory in the memory window I can see that the _TCHAR are taking two bytes each </p>
  
  <pre><code>o.p.e.n.c.v.-.l.o.g.o...j.p.g...
  6f 00 70 00 65 00 6e 00 63 00 76 00 2d 00 6c 00 6f 00 67 00 6f 00 2e 00 6a 00 70 00 67 00 00 00
  </code></pre>
  
  <p>Following the conversion recommendation in <a href="https://stackoverflow.com/a/159522/575530">another answer</a> I am trying to use <a href="http://msdn.microsoft.com/en-us/library/87zae4a3(v=vs.110).aspx" rel="nofollow noreferrer">ATL 7.0 String Conversion Classes and Macros</a> by inserting the following code:</p>
  
  <pre><code>char* filename = CT2A(argv[1]);
  </code></pre>
  
  <p>But the resulting memory is a mess, certainly not 'opencv-logo.jpg' as an ascii string:</p>
  
  <pre><code>fe fe fe fe fe fe fe fe fe fe ...
  þþþþþþþþþþ ...
  </code></pre>
  
  <p>Which conversion technique, function, or macro should I be using?</p>
  
  <p>(N.B. <a href="https://stackoverflow.com/q/1613217/575530">This</a> may be a related question but I cannot see how to apply <a href="https://stackoverflow.com/a/1616507/575530">the answer</a> here.)</p>