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 ?

Recommended Answers

All 3 Replies

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++;
}

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

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";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.