您的位置:首页 > 编程语言

常用代码片段

2014-06-10 15:40 183 查看
// input a line without spaces!

#inlcude <iostream>
char name[100]={};
cin>>name;

// input a line with space is stored.
string name1;
getline(cin, name1);

// start an .exe file from c++ code.

#include <windows.h>

{

system("timer.exe");
system("pause");

}

// calculate the run time of one part of code

#include <time.h>

{

clock_t start,finish;
double totaltime;
srand (1);

start=clock();

.....// your code here.

finish=clock();

totaltime=(finish-start)/static_cast<double>(CLOCKS_PER_SEC);
cout<<"totaltime for this code is: "<<totaltime<<" seconds."<<endl;

}

// sort  array

#include <algorithm> // std::sort

const int n = 1000000;
int * x= new int
; // use dynamic memory
for (int i=0; i<n; i++)
{
x[i]= rand();
}
sort(x, x+n);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: