954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

CSV file to Array C++

I'm a beginer in C++, and I've read number of posts regarding reading CSV files but have not understood how to convert them in to an array

my file reads just numbers that are seperated by tabs
23 34 67 78
45 56 89 90
23 45 79 23
33 14 74 78
etc.

Could someone please tell me how to convert this file into a 2 dimentional Array ?

neilconnexios
Newbie Poster
2 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Post the code where you read the file, that makes life a lot easier.

But you'll have to do something like:

while (lines in file)
{
    while (words in line)
    {
           storage[line][word] = inputread;
           word++;
    }
    line++;
}
Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

which object to use to seek if there are lines in the file and to check the words in line?

I know getline to obtain a whole line and eof to check end of the file but dont know how to pick up number from tab seperated file

neilconnexios
Newbie Poster
2 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

You can also use Getline with a third parameter as delimiter to obtain words.
Here's an example that reads a file word by word seperated by comma's

string word;
ifstream infile("something.csv");
while (getline(infile, word, ','))
{      
   	cout << "Word: " << word << "\n";
}
Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You