ここでは、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;
を
arr
使用することができますみたいで、実際の配列を定義しなければなりません? – iBug
@SomeprogrammerdudeそれはCSVです(間違ってCVSとタイプされていますが)。 [編集しました](/ posts/47493110 /リビジョン) – iBug
あなたは['using namespace std;'が悪い習慣である理由を知りました(https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice)。この場合、実際の問題を隠している混乱したコンパイルエラーが発生しました。あなたは、 "namespace std;を使用していることを完全に忘れることによって自分自身に恩恵を与えるでしょう。 C++に存在し、クラスやテンプレートへの完全修飾参照を書く方法を学ぶので、コンパイルエラーが発生したときには実際には意味があります。 –