博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++常见操作的模板
阅读量:4337 次
发布时间:2019-06-07

本文共 1559 字,大约阅读时间需要 5 分钟。

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

转载于:https://www.cnblogs.com/qujingtongxiao/p/9862380.html

你可能感兴趣的文章
vs无法加载项目
查看>>
Beanutils基本用法
查看>>
玉伯的一道课后题题解(关于 IEEE 754 双精度浮点型精度损失)
查看>>
《BI那点儿事》数据流转换——百分比抽样、行抽样
查看>>
哈希(1) hash的基本知识回顾
查看>>
Leetcode 6——ZigZag Conversion
查看>>
dockerfile_nginx+PHP+mongo数据库_完美搭建
查看>>
Http协议的学习
查看>>
【转】轻松记住大端小端的含义(附对大端和小端的解释)
查看>>
设计模式那点事读书笔记(3)----建造者模式
查看>>
ActiveMQ学习笔记(1)----初识ActiveMQ
查看>>
Java与算法之(2) - 快速排序
查看>>
Windows之IOCP
查看>>
机器学习降维之主成分分析
查看>>
WebSocket & websockets
查看>>
openssl 升级
查看>>
ASP.NET MVC:通过 FileResult 向 浏览器 发送文件
查看>>
CVE-2010-2883Adobe Reader和Acrobat CoolType.dll栈缓冲区溢出漏洞分析
查看>>
使用正确的姿势跨域
查看>>
AccountManager教程
查看>>