So yeah. HELP
Code:
Code:
Code:
Edit: Why do I always forget the error?
Edit 2: GRAAAAAAAAAAAAAAA WHY WHY WHY *cries*
Code:
Code:
#include <string>
#ifndef csv_h
#define csv_h
using namespace std;
class csv {
public:
csv();
string* parse(string values);
int rows(string values); int columns(string values);
string compose(string fields[], int values[], int rows);
private:
};
#endif
Code:
#include "csv.h"
using namespace std;
csv::csv(){
}
csv::string* parse(string values){
int rows = 0;
string rowContent[100];
int cols = 0;
string colContent[100];
int found = -1;
/* We need to figure out how many rows we have in out CSV string and seprate the CSV string into substrings*/
while(found != string::npos){
found = values.find("\n",0);
rowContent[rows] = values.substr(0,found-1);
values = values.subst(found+1);
if(found != string::npos)
rows++;
}
found = -1;
/* Now we need to figure out how many columns we have and seperate the rows into substrings*/
for(int i=0; i<rows; i++){
found = rowContent[i].find(",",0);
columnContent[cols] = rowContent[i].substr(0, found-1);
rowContent[i] = rowContent[i].substr(found+1);
if(found != string::npos)
cols++;
}
string ret[rows][cols];
for(int r=0; r<rows; r++){
for(int c=0l c<cols; c++){
ret[r][c]=columnContent[c];
}
}
return ret;
}
Code:
#include <iostream>
#include <string>
#include "csv.h"
using namespace std;
int main(){
string csvstring="Test, 123\nFun?,HELL NO\nTest is done?,YES";
csv parser();
string* values = parser.parse(csvstring);
for(int r=0; r<values.length(); r++){
for(int c=0; c<values[r].length(); c++){
cout << values[r][c] + " ";
}
cout << endl;
}
return 0;
}
Edit: Why do I always forget the error?
Edit 2: GRAAAAAAAAAAAAAAA WHY WHY WHY *cries*
Code:
main.cpp: In function ‘int main()’:
main.cpp:10:27: error: request for member ‘parse’ in ‘parser’, which is of non-class type ‘csv()’
main.cpp:11:25: error: request for member ‘length’ in ‘values’, which is of pointer type ‘std::string* {aka std::basic_string<char>*}’ (maybe you meant to use ‘->’ ?)