-5

Here is my code that I have written to read an excel file in csv format in C++. I want to read the file line by line. When I run the code it gives me an error saying

argument list for class template 'array' is missing

Thanks.

#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;
Wilfred Labue
  • 43
  • 3
  • 13
  • What are you thinking `array` is??? – iBug Nov 26 '17 at 04:41
  • @Someprogrammerdude It's CSV (although wrongly typed as CVS). [I've edited it](/posts/47493110/revisions). – iBug Nov 26 '17 at 04:43
  • 3
    You've just discovered why [`using namespace std;` is bad practice](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) since, in this case, it resulted in a confusing compilation error that hid the real problem. You will do yourself a favor by completely forgetting that "using namespace std;" exists in C++, and learn how to write fully-qualified references to classes and templates, so that when you do get a compilation error, it might actually be meaningful. – Sam Varshavchik Nov 26 '17 at 04:46
  • 1
    Possible duplicate of [How can I read and parse CSV files in C++?](https://stackoverflow.com/questions/1120140/how-can-i-read-and-parse-csv-files-in-c) – user0042 Nov 26 '17 at 07:23

1 Answers1

1

Since you declared using namespace std and included <array>, array is not a variable, but a template class (C++11 STL). You must define an actual array with it like

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

Then you'll be able to use arr afterwards

iBug
  • 35,554
  • 7
  • 89
  • 134