小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

在vs2008?C++下調(diào)試控制臺程序的心得及技巧

 flytl 2010-09-18

在vs2008 C++下調(diào)試控制臺程序的心得及技巧

 

Visual Studio 2008環(huán)境與VC6.0的環(huán)境存在著比較大的區(qū)別,下面就一些小小的區(qū)別在這里做一些探討,歡迎指教!

1、如果是調(diào)試控制臺程序,很多時候點擊“啟動調(diào)試”后是一閃而過,此時可有兩種方法讓cmd下dos調(diào)試屏幕暫停:

A:不要直接點擊vs2008的“啟動調(diào)試”按鈕,而是按Control+F5組合鍵。

B:在主函數(shù)main()里“return 0;”前加上兩句:cin.get();樣式如下

eg: int main()
          {
              cout<<"這是一個調(diào)試屏幕暫停的例子!"<<endl;
              cin.get();
              cin.get();
              return 0;
         }

2、類、函數(shù)和變量是C++編譯器的標(biāo)準(zhǔn)組件,它們都放置在名稱空間std中(此時頭文件沒有后綴名h)。在vs2008 C++下,如果不包含using namespace std;指令,那么必須使用std::前綴,如

#include "stdafx.h"
#include<iostream>   //頭文件沒有h后綴名

void simon(int); //函數(shù)原型

//using namespace std;     沒有使用std名稱空間

int _tmain(int argc, _TCHAR* argv[])
{
simon(3);
std::cout<<"請輸入一個整數(shù): "; //必須使用std::前綴,以下都是
int count;
std::cin>>count;
simon(count);
std::cout<<"完成!"<<std::endl;

std::cin.get();//這兩行是使調(diào)試屏幕暫停,不會一閃而過
std::cin.get();//讓程序等待鍵擊
return 0;//退出主函數(shù)
}

void simon(int n) //自定義函數(shù)
{
std::cout<<"現(xiàn)在整數(shù)是 "<<n<<"測試!"<<std::endl;
}

下面是一個使用using namespace std;名稱空間的對比:

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

void simon(int);

using namespace std; //這是一個使用std;名稱空間的例子

int _tmain(int argc, _TCHAR* argv[])
{
simon(3);
cout<<"請輸入一個整數(shù): ";
int count;
cin>>count;
simon(count);
cout<<"完成!"<<endl;

cin.get();
cin.get();
return 0;
}

void simon(int n)
{
cout<<"現(xiàn)在整數(shù)是: "<<n<<" 測試!"<<endl;
}

還有一種方法,就是既不使用std;名稱空間,也不使用std::前綴,而是使用using編譯指令。如:

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

using std::cout; //直接使用using指令
using std::cin;
using std::endl;


void simon(int);

//using namespace std; //這是一個既沒有使用std;名稱空間也沒有使用std::前綴的例子

int _tmain(int argc, _TCHAR* argv[])
{
simon(3);
cout<<"請輸入一個整數(shù): ";
int count;
cin>>count;
simon(count);
cout<<"完成!"<<endl;

cin.get();
cin.get();
return 0;
}

void simon(int n)
{
cout<<"現(xiàn)在整數(shù)是: "<<n<<" 測試!"<<endl;
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多