
/**//************************************************************************/
/**//* 使用結構體作為返回值 */
/**//************************************************************************/
#include "iostream.h"
struct student

{
int id;
char name[20];
int age;
char department[20];
float gpa;
};
student init(); //初始化,返回一個student的結構
void display(student arg); //顯示結構體
int main()

{
display(init()); //init()返回的是一個student結構體
return 0;
}
void display(student arg)

{
cout<<"學號:"<<arg.id<<" 姓名:"<<arg.name<<" 年齡"<<arg.age<<" 專業:"<<arg.department<<" 成績:"<<arg.gpa<<endl;
}
student init()

{
student s1 =
{3221,"Tom",18,"Computer",86.33}; //初始化一個student的結構體
return s1; //返回一個student的結構體s1
}
/**//************************************************************************/
/**//* 數組直接選擇排序的簡單實現,沒有輸入輸出模塊 */
/**//************************************************************************/
#include "iostream.h"
void sort(int a[],int size);
int main()

{
int num[]=
{21,12,45,34,67,30,21,3,56,98,99};
sort(num,sizeof(num)/sizeof(int));
return 0;
}
void sort(int a[],int size)

{
for (int i=0;i<size;i++)
{
int min=a[i],min_i=i; //假設首元素是最小的,min_i表示是最小數字i坐標
for (int j= i;j<size;j++)
{
if (a[j]<min)
{
min=a[j];
min_i = j;
}
}
int temp = a[i]; //a[min_i]為找到的值最小的元素,要把最小的元素放在a[i]中
a[i] = a[min_i];
a[min_i]= temp;
}
}
/**//************************************************************************/
/**//* 簡單的求數組中最大值的函數調用方法 */
/**//************************************************************************/
#include "iostream.h"
int max(int a[],int size);
int main()

{
int num[]=
{12,34,32,45,65,99,33,56,58,97};
cout<<max(num,sizeof(num)/sizeof(int))<<endl;
return 0;
}
int max(int a[],int size)

{
int max = 0;
for (int i=0;i<size;i++)
{
if(max<a[i])
max=a[i];
}
return max;
}說到Visual C++的插件,大家可能只有想到Visual Assist吧。天真!行內開發的插件可只有這個!?下面介紹一下vc6.0的其他插件。
Visual Assist(強烈推薦)
網址:http://www.wholetomato.com/
功能:VA從5.0一直到現在的VAX,功能越來越強大,除了以前版本中的自動識別各種關鍵字,系統函數,成員變量,自動給出輸入提示,自動更正大小寫錯誤,自動標示錯誤等等以外,最新的版本中還在WorkSpace窗口中加入一個VA View,可以更方便的查找工程中的文件、類和變量。
WndTabs(強烈推薦)
網址:http://www.wndtabs.com/
功能:WndTabs主要是在編輯窗口中顯示了所有已經打開的文件,在VC中能夠更方便的操作這些文件,比如修改文件屬性,copy文件路徑、文件名等,并且還開放源代碼,你要是愿意的話,可以添加自己很興趣的功能。
LineCounter
網址: http://www.wndtabs.com/
功能:用來統計整個工程的代碼行數,包括總行數、代碼行數、注釋行數、空行數等,并且對多個工程一起統計時,不會把相同的文件計算多次.
Spelly
網址:http://www.wndtabs.com/
功能:一個拼寫檢查的插件,可以對整個文件或所選部分進行拼寫檢查,支持C/C++/C#, VB, Fortran 和HTML。
SourceStyler C++
網址:http://www.sourcestyler.com/
功能:此插件是針對C++的一個格式化工具,可以針對自己的編碼習慣,選擇一種編碼風格,也可以自己定義,而且定義非常詳細,有表達式、指針、模板、類、枚舉等十幾種,肯定能滿足你的需要。
Numega BoundsChecker(強烈推薦)
功能:是針對Visual C++6.0應用程序的最為全面的錯誤檢測工具。BoundsChecker 能自動指出靜態,堆棧內存錯誤和資源泄漏問題。BoundsChecker 能夠校驗最新的 Windows APIs,包括 ActiveX, DirectX, OLE/COM, ODBC等等。能夠發現與 Windows 平臺兼容性。
BCGControlBar Library
功能:非常好的一套應用于vc6的界面擴展類庫,輕松的作出 vc2003 的界面。并且給了各種界面例子,如vc.net、outlook、更換皮膚等等。
Comment Wizard
網址:http://m.shnenglu.com/fwxjj/
功能:Visual C++插件,提供了Visual C++源代碼注解標準化與自動化功能。在它的幫助下,您可快速創建標頭文件信息注解,文件中模塊注解, C++處理方式,以及C語言功能與歷史校正功能注解,等等。
String watch Microsoft Visual Studio add-in
網址:http://www.codeguru.com/cpp/v-s/devstudio_macros/debugging/article.php/c5989
功能:調試時查看字符串的。
Tabbar插件
網址:http://www.winmsg.com/cn/tabbar.htm
功能:顯示多tab的插件
轉載自:http://bbs.xgcollege.com/read.php?tid-1138.html

/**//************************************************************************/
/**//* 輸出常用的ASCII碼表 */
/**//************************************************************************/
#include "iostream.h"
int main()

{
for (int i=32;i<=127;i++)
{
cout<<(char)i; //強制類型轉換
}
return 0;
}

#include "iostream.h"
#include "iomanip.h"//為了使用setw()
int main()

{
char temp;
for (int i=32;i<=127;i++)
{
temp = i;
cout<<setw(2)<<temp; //setw(n) 設域寬為n個字符
if (i%16==15)
{
cout<<endl;
}
}
return 0;
}
#include "iostream.h"
/**//************************************************************************/
/**//* 使用遞歸最簡單的程序,實現f(n)=2*f(n)+3 */
/**//************************************************************************/
int f(int i);
int main()

{
for (int i=1;i<=8;i++)
{
cout<<"f"<<"("<<i<<")"<<"="<<f(i)<<endl;
}
return 0;
}
int f(int i)

{
if (i ==1)
{
return 1;
}
else
{
return 2*f(i-1)+3;
}
}
#include "iostream.h"
int main()

{
int year;
cin>>year;
if (year%4 ==0 && year%100!=0 || year%400 ==0)
{
cout<<"是閏年(leapyear)";
}
else
{
cout<<"不是閏年";
}
return 0;
}
#include "iostream.h"
int main()

{
for (int i=7;i>0;i--)
{
int p=i;
while (p--)
{
cout<<"*";
}
cout<<"\n";
}
return 0;
}
#include "iostream.h"
int main()

{
for (int i=1;i<=5;i++)
{
int p=i;
while (p--)
{
cout<<"*";
}
cout<<"\n";
}
return 0;
}
#include "iostream.h"
int main()

{
int sum = 10;
for (int i=1;i<=sum;i++)
{
int p=(sum -i)/2;
while (p--)
{
cout<<" ";
}
p=i;
while (p--)
{
cout<<"*";
}
cout<<"\n";
}
return 0;
}
#include "iostream.h"
int main()

{
int sum = 10;
for (int i=sum;i>=0;i--)
{
int p=i;
while (p--)
{
cout<<" ";
}
p=sum -i;
while (p--)
{
cout<<"* ";
}
cout<<"\n";
}
return 0;
}
#include <stdio.h>
#include "iostream"
#include <string.h>
int main()

{
char *src = "hello";
int len= strlen(src);
char *dest = (char *)malloc(len+1);
char *d= dest;
char *s = &src[len-1];
len = 1;
while (len--)
{
*d++=*s--;
}
*d = 0; //否則會亂碼
printf("%s\n",dest);
free(dest);
return 0;
}
#include <stdio.h>
#include "iostream"
#include <string.h>
int main()

{
char src[] = "hello";
int len = strlen(src);
char temp;
for (int i=0;i<len/2;i++)
{
temp = src[i];
src[i] = src[len-i-1];
src[len-i-1] = temp;
}
printf("%s\n",src);
return 0;
}

int main()
{
char* src = "hello,world";
int len = strlen(src);
char* dest = (char*)malloc(len+1);//要為\0分配一個空間
char* d = dest;
char* s = &src[len-1];//指向最后一個字符
while( len-- != 0 )
*d++=*s--;
*d = 0;//尾部要加\0
printf("%s\n",dest);
free(dest);// 使用完,應當釋放空間,以免造成內存匯泄露
return 0;
}
#include <stdio.h>
#include <string.h>
main()

{
char str[]="hello,world";
int len=strlen(str);
char t;
for(int i=0; i<len/2; i++)

{
t=str[i];
str[i]=str[len-i-1]; str[len-i-1]=t;
}
printf("%s",str);
return 0;
}