1.统计时间

#include<ctime>
clock_t startTime = clock();
code();
clock_t endTime = clock();
cout << endl<< "time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " s"<<endl;

2.读取文件

#include<iostream>
#include<fstream>
#include<cstdlib>
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"<<filename<<endl;
cout<<"Program terminating.\n";
exit(EXIT_FAILURE);
}
double value; //1
double sum=0.0;
int count=0; inFile>>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:"<<count<<endl;
cout<<"sum:"<<sum<<endl;
}
inFile.close();
return 0;
}

3.写入文件

#incluede<fstream>
ofstream outFile;
outFile.open("carinfa.txt"); //要放入的文件名
outFile<<... //放入的信息
.
.
.
outFile.close(); //关闭文件

4.产生0~89之间的随机数

#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
double target;
srand(time(0));
for(int i=0;i<=20;i++)
{
target=rand()%90;
cout<<target<<endl;
}
return 0;
}

6.传二维数组

int show(double* A,int row,int col)
{
int i,j;
double** B=new double*[col];
for(i=0;i<row;i++)
{
B[i]=new double[col];
}
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
B[i][j]=*(A+i*col+j);
cout<<B[i][j]<<" ";
}
cout<<endl;
}
for(i=0;i<row;i++)
{
delete[] B[i];
}
delete[] B;
}
//调用: show(A[0],4,7);

最新文章

  1. STM32F412应用开发笔记之一:初识NUCLEO-F412ZG
  2. vs 颜色设置
  3. JS生成某个范围的随机数(四种情况)
  4. eclipse cdt代码悬停窗口背景颜色设置(转载)
  5. Textbox像百度一下实现下拉显示 z
  6. oc-06-无参方法的调用
  7. 充分发挥 JavaScript 语言的优势
  8. Linux下文件及目录的一些操作(附递归遍历目录源码)
  9. FUDCon - FedoraProject
  10. JS禁用右键,禁用打印,防止另存为,IE浏览器识别(转载)
  11. WPF popup置顶
  12. vue学习笔记(四)——Vue实例以及生命周期
  13. Hessian探究(一)Hessian与springMVC结合
  14. jq实现多选反选
  15. 用tensorflow实现最简单的神经网络
  16. flask接收post提交的json数据并保存至数据库
  17. 第44节:Java当中的JVM
  18. CentOS 6 升级 curl
  19. 运行python文件时出错SyntaxError: Non-UTF-8 code starting with &#39;\xb5&#39; in file, but no encoding declared;
  20. codeforces590b//Chip &#39;n Dale Rescue Rangers//Codeforces Round #327 (Div. 1)

热门文章

  1. to_string函数(将数字转换成字符串)
  2. reduce &amp; fold in Spark
  3. js倒计时demo 天/时/分/秒
  4. 线段树合并(【POI2011】ROT-Tree Rotations)
  5. webpack中关于require与import的区别
  6. 2019-03-18 用Task Schedule定时调用Python脚本
  7. mycql 基本mysql语句(增删改查)
  8. 通过rpm安装jdk
  9. STM32 USB转串口驱动安装不成功出现黄色感叹号解决方法!
  10. vue自定义一个过滤器