65,184
社区成员




#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
ifstream infile("data.txt");
if (infile.is_open())
{
int total;
infile>>total;
double *num=new double[total];
while (!infile.eof())
{
infile >> *num;
cout<<*num << '\t';
num++;
}
}
else
{
cout<<"Error,can't open...\n";
exit(2);
}
return 0;
}
CFileException pError;
CString strLineCont;
if (TRUE == m_stdFileEx.Open("input.txt", CFile::modeRead|CFile::typeText, &pError))
{
while(m_stdFileEx.ReadString(strLineCont)) //逐行读取内容到strLineCont中
{
//你自己的操作
}
m_stdFileEx.Close();
return true;
}
else
{
MessageBox(NULL,_T("文件不能读入\n文件正在打开或使用中!"),_T("读取文件失败"), MB_OK|MB_ICONINFORMATION);
return false;
}
ifstream infile;
infile.open ("test.txt");
if (infile.is_open())
{
int num;
float *pf, *p;
infile >> num;
pf = new float[num];
p = pf;
while (infile.good()) {
infile >> *p++;
cout << *(p-1) << endl;
}
infile.close();
}
else
{
cout << "Error opening file";
}
ifsream inputfile("input.txt");
int count ;
inputfile >> count;
for (int i = 0; i < count; i++)
inputfile >> num[i];