int main( int argc, char* argv )
// You can get these values from std::cin
// I'm hard-coding for simplicity
int row = 5;
int width = 25;
// Vectors, by their nature, can resize dynamically
// However, we can also preset desired sizes
str_vec.resize( row );
for( auto &i : str_vec )
i.resize( width );
// You can assign and access just like a regular 2D array
str_vec = "This is a string!";
std::cout << str_vec << std::endl;
// You can get current size by using size()
std::cout << "Current size of row vector: " << str_vec.size() << std::endl;
std::cout << "Current size of width vector: " << str_vec.size() << std::endl;
Crashing like "program stop working" "Process terminated with status -1073741510 (0 minutes, 12 seconds)", it crasching when i want put some information into strings. clines1(); scan file from which i read and put in numberlines number of rows.
@iHutch105: Your examples are column-major. C/C++ is row-major. Nefri's attempt mixed the indices. On a square matrix one would not notice the error.
On the other hand there is reading from input too without checking whether (malformed) input adds too many words per line and too many lines.
std::ifstream opened with fstream::out flag?
The static array is a continuous block of memory. The dereference operation(s) on array does "pointer math" in order to retrieve desired element.
One can use dynamic 2D array with only 2 'new ' and 2 'delete '. One reserves a block of rows*cols for the data, and the second reserves rows pointers to the beginning of each row within the block. On iHutch105's model there are multiple separate small blocks, rather than one for the data.
One could possibly use a std::string (*arr); instead of the array of pointers to data block(s), reducing the need to one 'new ' and one 'delete '.
Cheers, Keskiverto. In hindsight, I should have probably gone with row/col, rather than row width, as I would have been less inclined to mix up the order that way. In fact, I'm not even sure why I didn't. I think I may have been blindly copying.