1.统计时间
#include clock_t startTime = clock();code();clock_t endTime = clock();cout << endl<< "time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " s"<
2.读取文件
#include #include #include const int SIZE=60; int main(){ using namespace std; char filename[SIZE]="information.txt"; ifstream inFile; inFile.open(filename); if(!inFile.is_open()) { cout<<"Could not open the file"< < >value; //1 while(inFile.good()) { ++count; sum=sum+value; inFile>>value; } if(inFile.eof()) cout<<"end of file reached.\n"; else if(inFile.fail()) cout<<"input terminated by data mismatch.\n"; else cout<<"input terminated for unknown reason.\n"; if(count==0) cout<<"NO DATA PROCESSED.\n"; else{ cout<<"items read:"< <
3.写入文件
#incluede ofstream outFile;outFile.open("carinfa.txt"); //要放入的文件名outFile<<... //放入的信息...outFile.close(); //关闭文件
4.产生0~89之间的随机数
#include #include #include using namespace std;int main(){ double target; srand(time(0)); for(int i=0;i<=20;i++) { target=rand()%90; cout< <
6.传二维数组
int show(double* A,int row,int col){ int i,j; double** B=new double*[col]; for(i=0;i