.csv file with searching

My .csv file is like:
Bone,origin,deep/superficial,location, action
frontal, membranous connective tissue, deep, cranial, flexes arm
parietal, catilage, superficial, cranial, raises shoulder
and so forth.

This is my main.cpp file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <cstdlib>
#include "Action.h"
#include "Action.cpp"

using namespace std;

void readCSV(istream &input, vector< vector<string> > &output)
{
        string csvLine;
        // read every line from the stream
        while( getline(input, csvLine) )
        {
                istringstream csvStream(csvLine);
                vector<string> csvColumn;
                string csvElement;
                // read every element from the line that is seperated by commas
                // and put it into the vector or strings
                while( getline(csvStream, csvElement, ',') )
                {
                        csvColumn.push_back(csvElement);
                }
                output.push_back(csvColumn);
        }
}

int main()
{
        fstream file("bones.csv", ios::in);
        if(!file.is_open())
        {
                std::cout << "File not found!\n";
                return 1;
        }
        // typedef to save typing for the following object
        
        csvVector csvData;

        readCSV(file, csvData);
        
        Queries queries(csvData);

system ("PAUSE");
return 0;
}


This is my action.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include "Action.h"

using namespace std;

Queries::Queries(csvVector csvData)
{
      int column_index;
      string value;
      cout << "What type do you want to find?" << endl
     << "(0) Bone" << endl
     << "(1) Origin" << endl
     << "(2) deeporsuperficial" << endl
     << "(3) Location" << endl
     << "(4) Action" << endl;

      cin >> column_index;
      
    cout << "What is the value for that type you want to find?" << std::endl;
    cin >> value;

    for(size_t i = 0; i != csvData.size(); ++i)
  {
    if(csvData[i][column_index] == value)
    {
      // The row is found
      for(vector<string>::iterator j = csvData[i].begin(); j != csvData[i].end(); ++j) // Output the row items
      {
        cout << *j << ", ";
      }
    }
    cout << "\n";
  }
}
 


This is my action.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef _ACTION_H_
#define _ACTION_H_

#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;

typedef std::vector< std::vector<std::string> > csvVector;

class Queries {
public:
     Queries(csvVector csvData);

private:
    string bones;
    string origin;
    string location;
    string action;
    string deeporsuperficial;
};

#endif 


These are the errors I get:
line 10 on action.h: error: expected ')' before 'csvData'
line 6 on action.cpp: error: expected constructor, destructor, or type conversion before '(' token

Please Help. I would greatly appreciate it :]
Last edited on
Move your typedef of csvVector to action.h because Queries class doesn't know what a csvVector is. Also #include <vector>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef _ACTION_H_
#define _ACTION_H_

#include <iostream>
#include <cstdlib>
#include <vector> // add include here

using namespace std;

typedef std::vector< std::vector<std::string> > csvVector;

class Queries {
public:
     Queries(csvVector csvData);

private:
    string bones;
    string origin;
    string location;
    string action;
    string deeporsuperficial;
};

#endif  


In main.cpp you should not include action.cpp, remove it. Also remove the typedef.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <cstdlib>
#include "Action.h"
// #include "Action.cpp" // remove this

...
// typedef std::vector< std::vector<std::string> > csvVector; // remove this
...




If I remove "Action.cpp" in my main.cpp it returns "[linked error] undefined reference to 'Queries::Queries[std::vector<std::vector<std::string<std::allo....
ID returned 1 exit status.

If I do not remove that, it askes me "What type do you want to find?"
I enter a number.
Then it askes me:
"What is the value for that type you want to find?"

I tried entering numbers and words, it does not return anything.
Last edited on
Someone please help me!!!!! :]


I want this program to do three things:
1) Ask user for action, it will return the bones.
2) Ask user to enter word strengthen followed by location. It will return the bones.
3) Ask user bone, it will return location and whether it's deep/superficial.
Topic archived. No new replies allowed.