2011년 4월 17일 일요일

cpp] main _tmain

2010을 처음 깔고 console application을 실행하려고 보니. main 이 없는것이다.
---------------------
stackoverflow.com에서...


_tmain is a macro that gets redefined depending on whether or not you compile with Unicode. It is a Microsoft extension and won't work on any other compilers.

--; tmain은 마소꺼고 다른 컴파일러에서 안 돌아간다.

The correct declaration is
 int _tmain(int argc, TCHAR *argv[])
If the macro UNICODE is defined, that expands to
int wmain(int argc, wchar_t *argv[])
Otherwise it expands to
int main(int argc, char *argv[])
Your definition goes for a bit of each, and (if you have UNICODE defined) will expand to
 int wmain(int argc, char *argv[])
which is just plain wrong.
std::cout works with ASCII characters. You need std::wcout if you are using wide characters.
try something like this
#include <iostream>
#include <tchar.h>
#if defined(UNICODE)
    #define _tcout std::wcout#else
    #define _tcout std::cout#endif
int _tmain(int argc, TCHAR *argv[]) {
   _tcout << _T("There are ") << argc << _T(" arguments:") << std::endl;

   // Loop through each argument and print its number and value
   for (int i=0; i<argc; i++)
      _tcout << i << _T(" ") << argv[i] << std::endl;

   return 0;
}

이런 예제도 있었는데.

// first.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    cout << "There are " << argc << " arguments:" << endl;   // Loop through each argument and print its number and value
    for (int i=0; i<argc; i++)      cout << i << " " << argv[i] << endl; 
   
 return 0;
}


요렇게 해도 되고.



// first.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;
int main(int argc, _TCHAR* argv[])
{
    cout << "There are " << argc << " arguments:" << endl;   // Loop through each argument and print its number and value
    for (int i=0; i<argc; i++)      cout << i << " " << argv[i] << endl; 
   
 return 0;
}


요렇게 _tmain을 main으로 바꿔도 되더라.


그런데 iostream.h는 어디간거징. 강사님이 .h가 안 붙는 것은 표준이라고 하셨다.

 잘 모를 때는 표준만 써야하겠다.





댓글 없음:

댓글 쓰기

국정원의 댓글 공작을 지탄합니다.

UPBIT is a South Korean company, and people died of suicide cause of coin investment.

 UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...