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).

hawkeye
  • 349
  • 4
  • 21
  • `file.good()` is **not** the opposite of `!file.fail()` – Cheers and hth. - Alf May 23 '14 at 07:08
  • Since you are writing a parser, also have a look how to do it [using Boost.Spirit](http://stackoverflow.com/a/1764367/1968). That’s by far the easiest, most robust and probably also the most efficient way. However, it has a steep learning curve. – Konrad Rudolph May 23 '14 at 07:09
  • boost::spirit is indeed a good parser but it would be overkill for just reading a bunch of strings into an array – jasal May 23 '14 at 07:21

1 Answers1

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);
}
jasal
  • 1,044
  • 6
  • 14