关于返回vector
大家好,请教下如何返回一个vector类,我知道运行完read函数后,vector<float> arr_name的内存会释放掉,那我怎么写才对这个程序,另外我想读取的txt文件,我不知道文件中数据的数目,用while来判断是否读到文件尾这种方法行吗?谢谢大家 !!
程序代码:#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
vector<float> read(string name);
int main()
{
vector<float> abc;
yxz = read("yyy.txt");
vector<float>::iterator p;
for(p=yyy.begin();p!=yyy.end();p++)
{
cout<<"p =="<<*p<<endl;
}
return 0;
}
vector<float> read(string name)
{
vector<float> arr_name;
ifstream fin;
fin.open("name");
float value;
while(!fin.eof())
{
fin>>value;
cout<<"value =="<<value<<endl;
arr_name.push_back(value);
}
fin.close();
return arr_name;
}







