How to create a 2d string array and take string as input into the array?
How to create a 2d string array and take string as input into the array?
Last edited on
Spanish inquisition?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <string>
#include <vector>
int main()
{
std::vector<std::vector<std::string>> foo( 3, std::vector<std::string>( 4, "bar" ) );
for ( auto & row : foo )
{
std::cout << "Enter row, please:\n";
for ( auto & elem : row )
{
std::cin >> elem;
if ( ! std::cin ) return 1; // input failure
}
}
std::cout << "\n===\n";
for ( const auto & row : foo )
{
for ( const auto & elem : row )
{
std::cout << elem << ' ';
}
std::cout << '\n';
}
return 0;
}
|
Topic archived. No new replies allowed.