2017-04-12 34 views
0

中にエラーが発生したI正しくコンパイルし、次のコードを持っている:実行可能ファイルが実行

#include <iostream> 
#include <iomanip> 
#include <fstream> 
#include <string> 
#include "INVESTMENT.h" 
#include <vector> 
using namespace std; 


int main() 
{ 


    ifstream inputFile("jroth.csv"); 
    string sHolder; //used as placeholder for string 
    float fHolder; //used as placeholder for float 
    double dHolder; ///used as placeholder for double 

// while (inputFile.good()) 
    vector<int> InvestVector; //will hold class (Investment) which contains string, double, and float 
    for (int i=0; i <= 7; i++) 
    { 
     Investment InvestVector[i]; //create new class for each line being pulled from .csv file 
     getline(inputFile, sHolder, ','); //pull in investment symbol as string 
     InvestVector[i].setSymbol(sHolder); //store string in the class 
     cout << InvestVector[i].getSymbol(); //verify string store properly 
    } 

    return 0; 
} 

とすぐにプログラムが実行されるよう、実行可能なクラッシュ。なぜどんな考え?

Investment InvestVector[i]; 

0からI-1までの番号「i」の場所を持つ配列を作成します。この行は、あなたが標準C++ではない可変長配列とC++コンパイラを使用していると仮定すると

+6

洞察の仕方でデバッガは何を提供していますか?もしあなたがC++を初めて使っているのであれば、 'namespace stdを使う 'という悪い習慣を避けるようにしてください。 'std ::'プレフィックスは意図的なもので、独自のコード内の名前との衝突を避けるのに役立ちます。 – tadman

+0

ここには「投資」とは何も表示されていません。そこにはどんな数のことが起こっているかもしれません。ヘッダーファイルがすべて大文字になっている理由はありますか? – tadman

+0

'for'ループでは、C++標準ではサポートされていない*ダイナミック配列*を使用しています。 –

答えて

0

。そして、この2行:

InvestVector[i].setSymbol(sHolder); 
cout << InvestVector[i].getSymbol(); 

は、配列の最後過去1である配列の位置番号「I」で動作するようにしようとします。

関連する問題