65,174
社区成员




using namespace std;
ifstream fin("data.txt");
vector<int> vec;
copy(istream_iterator<int>(fin), istream_iterator<int>(), back_insert_iterator<vector<int> >(vec));
还有更简单的~int main()
{
int a[16] = {0};
FILE* fp = fopen("aa.txt", "r");
int i = 0;
while (!feof(fp))
{
fscanf(fp, "%d", &a[i]);
i++;
}
return 0;
}
ifstream fin("data.txt");
vector<int> vec;
while (fin)
{
int idata;
fin >> idata;
vec.pushback(idata);
}
很难吗?#include <iostream>
#include <stdio.h>
#include <fstream>
#include <stdlib.h>
#include < sys\stat.h>
using std::ios;
using std::string;
using namespace std;
int main()
{
size_t txtlen;
char ch=0;
char* t;
struct _stat info;
int a=0;
std::ifstream text("123.txt", std::ios::in);
_stat("123.txt", &info);
txtlen = info.st_size;
t=( char *)malloc(txtlen*sizeof(char));
if(!t)
{
printf("创建动态数组失败!\n");
exit(-1);
}
while(!text.eof() && a<txtlen)
{
text.get(ch);
if((ch!=' ')&&(ch!=10)&&(ch!=13))
{
t[a]=ch;
a++;
}
}
text.close();
for(int i=0;i<a;i++)
cout<<t[i]<<" ";
return 0;
}
就是想问,上面那个图中的矩阵,怎么存储到一个一维数组中? 问题太多 说具体一点 简要一点
问题太多 说具体一点 简要一点