C++ 배열로 읽으려고하는 파일 (한 줄에 하나씩)에 이중 숫자가 있습니다. 실행하는 동안 나는 아래의 코드를 사용하지만, 아래의 오류가 발생하고있다 :단순 파일에서 double 배열을 읽습니다.
세그먼트 오류를 : 11
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main() {
string line;
ifstream myfile ("temp2.csv");
std::vector<double> myArray;
int index = 0;
if (myfile.is_open())
{
while (! myfile.eof())
{
getline (myfile,line);
cout << line << endl;
// myArray[index++] << line;
myArray[index++] = atoi(line.c_str());
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
시주의 사항 '으로 간주된다 나쁜 관행 (http://stackoverflow.com/questions/5605125'그/why-is-iostreameof-inside-a-loop-condition-considered-wrong). – Rakete1111
파일의 모양은 무엇입니까 – thermite
왜 이건 속임수를 찾을 수 없습니까?!? 문제는 벡터가 비어있는 것입니다. – NathanOliver