2017-11-26 12 views
-5

ここでは、C++でCSV形式のExcelファイルを読み込むために作成したコードを示します。ファイルを1行ずつ読みたい。私は、コードを実行すると、それは私にエラーを与えるクラステンプレート「配列」の言っC++でCSVファイルを読む方法

引数リストが

感謝が不足しています。あなたがusing namespace stdを宣言し、<array>を含むので

#include <string> 
#include <iostream> 
#include <iomanip> 
#include <fstream> 
#include <array> 

using namespace std; 
int main() { 
array<string , 29>arr; 
string line; 
int location; 
int start = 0; 

//int arrayFile[51][28] = { { 0 } }; 
string fileName; 
ifstream infile(fileName); 
infile >> line; 

//error check 
if (infile.fail()) { 
    cout << "File not Found !" << endl; 
    exit(1); 
} 

//reading the file 

for (int i = 0; i < 29; i++) { 
    location = line.find(","); //find the first comma in line 
    array[i] = line.substr(start, location - start); // separate the information from line up to the comma 
    line = line.substr(location + 1); //change line to the rest after removing the the abouve piece of the information 

} 
array[i] = line; 
+0

arr使用することができます

array<string, 29> arr; // std::array<std::string, 29> arr; 

みたいで、実際の配列を定義しなければなりません? – iBug

+0

@SomeprogrammerdudeそれはCSVです(間違ってCVSとタイプされていますが)。 [編集しました](/ posts/47493110 /リビジョン) – iBug

+3

あなたは['using namespace std;'が悪い習慣である理由を知りました(https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice)。この場合、実際の問題を隠している混乱したコンパイルエラーが発生しました。あなたは、 "namespace std;を使用していることを完全に忘れることによって自分自身に恩恵を与えるでしょう。 C++に存在し、クラスやテンプレートへの完全修飾参照を書く方法を学ぶので、コンパイルエラーが発生したときには実際には意味があります。 –

答えて

1

は、arrayは変数ではなく、テンプレートクラス(C++ 11 STL)。あなたがあるarray` `何を考えているそして、あなたはその後

+0

私は実際の配列を定義していますが、まだ動作していません。 –

+0

@WilfredLabueここに主張するのではなく、質問に編集してください。 – iBug

+0

@WilfredLabueなぜ、後のコードで 'array'に固執していますか? – iBug

関連する問題