c++ - Printf and cout only printing first character of args cpp -


i may missing point here have following method print out args in cpp program in visual studio:

int _tmain(int argc, char* argv[]) {      char* fu = "bar";      std::cout << "test, " << argc << ", " << argv[0] << ", " << argv[1] << ", " << fu << endl;         printf("%s, %s, %s", argv[0], argv[1], fu);     return 0; } 

the problem having seems print first character of args , not whole string.

from can tell, argv[0] dereferences argv array char*, , passing cout/printf functions. should print characters \0 character.

i created test char* fu see if problem passing in char* functions, 'bar' printed.

the thing can think because size of fu known @ compile time , size of argv isn't funny going on way compiled.

i know can print out contents looping through characters seems defeat point, example if want work strings comparison or something. can please explain what's going on?

either change _tmain main, or change char tchar , printf _tprintf. should using tchar-based facilities consistently, or not @ all.

it's clear building unicode build, , parameters passed wchar_t* pointers, not char*. treating them if char*, program exhibits undefined behavior.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -