1

I am having a csv file which I converted from .mat file and the size of the CSV file is 10161 and the it is stored in 10161 rows and 1 column.

I can extract the csv files when they are in 10161 columns and 1 row but I am unable to do the vice versa.

ifstream file("lbl_all.csv"); 

string value;
int s;
int result = 0 ;
while ( file.good() )
{   

getline ( file, value, ',' ); 

string( value, value.length()-2,1 ); 
}

But here I am able to extract it but it coming in diff rows and 1 column.

Suggest me a way to extract it and store it in an array of size(10161,1).

3
  • file.good() is not the opposite of !file.fail() Commented May 23, 2014 at 7:08
  • Since you are writing a parser, also have a look how to do it using Boost.Spirit. That’s by far the easiest, most robust and probably also the most efficient way. However, it has a steep learning curve. Commented May 23, 2014 at 7:09
  • boost::spirit is indeed a good parser but it would be overkill for just reading a bunch of strings into an array Commented May 23, 2014 at 7:21

1 Answer 1

0

If I understood right your file looks like this:

value
value
value

Assuming this is the case you can read it like that:

std::ifstream file("lbl_all.csv");
std::string line;
std::vector<std::string> lines;
while (std::getline(file, line))
{
  lines.push_back(line);
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.