2017-04-06 14 views
-1

ビルド時に私のプログラムに厄介な問題があります。エラーはありませんが、実行すると、ターミナルに "終了コード11で終了しました"と書かれています。実際にそれは無効ですが、私は私のメインで起動します)csvをC++の終了コード11で解析する

ありがとうございます。通常

C++プログラムは、より多くのようになります:

int main() 
{ 
    // code 
    return 0; 
} 

void getData2(ifstream& infile, Stock stocks[], int dataSize) 
{ 
    // Get the data 
} 

エラー11がセグメンテーション違反可能性があり、実際の答えとして私の応答を修正再表示

void getData2 (ifstream& infile, Stock stocks[], int dataSize) 

string token ; 

const char delim = ','; 

for (int i = 0; i < dataSize; i++) 
{ 
    getline(infile, stocks[i].date, delim); 
    infile >> stocks[i].open ; infile.ignore(10, delim); 
    infile >> stocks[i].high ; infile.ignore(10, delim); 
    infile >> stocks[i].low ; infile.ignore(10, delim); 
    infile >> stocks[i].close ; infile.ignore(10, delim); 
    infile >> stocks[i].volume ; infile.ignore(10, delim); 
    infile >> stocks[i].ajdclose ; infile.ignore(10, delim); 

} 

for (int i = 0; i < dataSize; i++) 
{ 
    cout << stocks[i].open; 
} 
+0

は、我々はあなたが – chbchb55

+2

から読んでいるファイル、通常はあなたのコード – chbchb55

答えて

0

コードには開始予定のエントリポイントがありません。

0

確か

#include <iostream> 
#include <fstream> 
#include <string> 
#include <vector> 
#include <sstream> 
#include <iomanip> 
#include <cmath> 

using namespace std; 

int main() 

struct Stock 
    string date; 
    double open; 
    double high; 
    double low; 
    double close; 
    long volume; 
    double ajdclose; 
; 

void getData2(ifstream& infile, Stock stocks[], int dataSize); 

ifstream infile("/Users/emmanl/CLionProjects/ING.csv"); 

if (!infile) { 
    cout << "File not open\n"; 
    return 1; 
} 

//stock vector init 
Stock stocks[] = {}; 

//size to automate 
const int Sizefile = 22; 

//get data from yahoo files and input in struct 
getData2(infile, stocks, Sizefile); 


return 0; 
+0

の残りの部分Cになり++のプログラムを見ることができるより多くのような '' ' int型のmain(){ //コード リターン0; }ボイドgetData2(はifstream&INFILE、在庫ストック[]、INT DATASIZE) {//データを取得 }エラー11がセグメンテーション違反であってもよいです。 –

+0

OK!お返事ありがとうございました –

+0

あなたが回答として私の再定式化された答えにフラグを付けるのに十分親切であれば、私はそれを感謝します。 –

関連する問題