I want to store the content of .txt file in a 2D array. I am a beginner in c++ and I don't know how to do that.
So, currently, I can read from a file and display it content. Moreover, I can store in a buffer (std::string)
This is my code :
#include <iostream>
#include <fstream>
int main( int argc, char* argv[] )
{
std::ifstream inFile;
inFile.open(argv[1]);
if(!inFile) {
std::cout << "Unable to open file: " << argv[1] << std::endl;
return -1;
} else {
std::string str((std::istreambuf_iterator<char>(inFile)),
std::istreambuf_iterator<char>());
std::cout << str;
inFile.close();
}
return 0;
}
My .txt file looks like that
cat file.txt
----------
| |
| |
| |
| |
----------
So, can you help to find the best way to store my file in a 2D array ? Do you know what is the best way to do that ?
Thank you for answers