c++ program why this output?

Hi
I wrote the following program is Vs2008, c++, console application

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
cout << "prog name is: " << argv[0];
cout << "first parameter is: " << argv[1];
cout << "second parameter is: " << argv[2];
}

I got a strange output like
prog name is: 004A1F94 first parameter is : 004A1FAA ...
Why?
argv[] is _TCHAR*, and cout only considers char* a string, so it treats _TCHAT* as any other pointer and prints its value. cout << (char*)argv[];
Last edited on
Ok
I found it
My program works if
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main(int argc, char * argv[])
{
cout << "prog name is: " << argv[0];
cout << "first parameter is: " << argv[1];
cout << "second parameter is: " << argv[2];
}
But why?
Topic archived. No new replies allowed.