1. ホーム

vs環境でのc++のメイン_tmainとコンソールプログラムが、キーを押しても続行しないまま終了する問題

2022-02-25 06:53:58

ビデオチュートリアルは、VC6でコンパイルして実行します。私のパソコンにVC6をインストールするのに問題があったので、vs2003をインストールしたところ、多くの問題が見つかりました。

新しいビルドの後、このパラグラフが出てきました。

#include "stdafx.h"



int _tmain(int argc, _TCHAR* argv[])



{






return 0;



}

main()を下に書くということは、オーバーロードできないことを示唆しています。

百度に聞いて、使える人はブックマークしてください:。

People who have used C know that every C program will have a main(), but sometimes look at the program written by others to find the main function is not int main(), but int _tmain(), and the header file is not <iostream.h> but <stdafx.h>, will be confused, right?
Let's see what they have to do with each other
First of all, the _tmain() is an alias for the main used to support unicode, since it is an alias, there should be a macro defined, where is it defined? In that confusing <stdafx.h>, there are two lines.

#include <stdio.h>
#include <tchar.h>

 We can find the macro definition for _tmain in the header file <tchar.h> 

#define _tmain main

 So, after pre-compiling, _tmain becomes main, now you know!

This passed, but the problem came back when the command prompt appeared after successful compilation and then flashed without displaying

press any key to continue
Find Baidu again, so that.

#include "stdafx.h"
#include "stdlib.h"
int _tmd()
{
	
	std::cout<<"This is my first C++ program \n";
	int x;
	std::cin>>x;
	std::cout< system("pause");
	return 0;
}

or

#include "stdafx.h"
#include "conio.h"
int _tmain()
{
	
	std::cout<<"This is my first C++ program \n";
	int x;
	std::cin>>x;
	std::cout<<x;
	
	
	getch();
	return 0;
}

 2 solutions.

Back it up yourself so you don't forget it in the future.

Link.

#include <stdio.h>
#include <tchar.h>

 We can find the macro definition for _tmain in the header file <tchar.h> 

#define _tmain main

 So, after pre-compiling, _tmain becomes main, now you know!


This passed, but the problem came back when the command prompt appeared after successful compilation and then flashed without displaying

press any key to continue

Find Baidu again, so that.

#include "stdafx.h"
#include "stdlib.h"
int _tmd()
{
	
	std::cout<<"This is my first C++ program \n";
	int x;
	std::cin>>x;
	std::cout< system("pause");
	return 0;
}


or

#include "stdafx.h"
#include "conio.h"
int _tmain()
{
	
	std::cout<<"This is my first C++ program \n";
	int x;
	std::cin>>x;
	std::cout<<x;
	
	
	getch();
	return 0;
}

 2 solutions.

Back it up yourself so you don't forget it in the future.




Link.


http://blog.csdn.net/qq_25572699/article/details/43118999