C++中读取一个txt数值的程序
2016-02-23 15:12
435 查看
//写好一个ia.txt 里面写上数值
#include <iostream>
#include<fstream>
using namespace std ;
#define NUM 5000
int i ,Datalen=-1;
double Data[NUM];
int main()
{
ifstream fin("ia.txt");
if (!fin)
{
cout<<"Can not open datainl file"<<endl;
getchar();
return 1;
};
while(!fin.eof())
{
Datalen++;
if (Datalen>4999)
{
cout<<"too much data"<<endl;
getchar();
return 1;
}
fin>>Data[Datalen];
}
fin.close();
for (i=0;i<Datalen;i++)
{
cout<<Data[i]<<endl;
}
system("pause");
return 0;
}
#include <iostream>
#include<fstream>
using namespace std ;
#define NUM 5000
int i ,Datalen=-1;
double Data[NUM];
int main()
{
ifstream fin("ia.txt");
if (!fin)
{
cout<<"Can not open datainl file"<<endl;
getchar();
return 1;
};
while(!fin.eof())
{
Datalen++;
if (Datalen>4999)
{
cout<<"too much data"<<endl;
getchar();
return 1;
}
fin>>Data[Datalen];
}
fin.close();
for (i=0;i<Datalen;i++)
{
cout<<Data[i]<<endl;
}
system("pause");
return 0;
}
相关文章推荐
- ?十进制/二进制转换(C语言)
- C++中“wchar_t* ”和“ char * ”之间的相互转换
- 虚幻引擎 C++ 视频教程-01
- c++ 设计模式7 (Bridge 桥模式)
- Windows下C++ 串口编程实例
- [C++]static, virtual, const关键字
- C/C++ const char*如何转换成char*
- C++的namespace用法详解
- 1.C++远航之起航篇
- C++两个类相互引用的问题
- C语言笔记(1)
- C++ function、bind以及lamda表达式
- C++ STL vector
- 1033. To Fill or Not to Fill (25)
- ibc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
- 【C++】public protected private
- C-initialize your pointer before using
- C-MS Compiler Environment(VS2010) (特殊的编译环境)
- 折半查找笔记,C++实现
- VC ActiveX(ocx)双击全屏(C++版)