| shoficplusplus (3) | |
|
hi guys........i'm shofi. i am beginner in C++. how can i make list of 'n cities using 2D Array. Sample screen input/output: -How many cities do you want to enter? >>5 -Please enter the names of the 5 cities: >>New York >>Chicago >>Washington DC >>Boston >>Seattle -You entered 5 cities: New York, Chicago, Washington DC, Boston and Seattle can anyone help me about this .... i don't get from where i can start because i very beginner in C++ thanks | |
|
|
|
| Darkmaster (494) | |
| what is the 2nd dimension of that array for, if you only want to save names? | |
|
|
|
| MikeyBoy (235) | |
| If the OP has been given that as a requirement, then presumably the names are to be stored as char arrays, rather than as STL strings. | |
|
|
|
| shoficplusplus (3) | |
|
@Darkmaster so how can i do this ....in one-array? .......how? thanks shofi | |
|
|
|
| MikeyBoy (235) | |
| Use an array of std::string objects. Technically, that's a 1D array, although each string object probably contains a char array hidden inside it. | |
|
|
|
| shoficplusplus (3) | |
|
@MikeBoy can i get some code , please. | |
|
|
|
| Darkmaster (494) | |
|
i would use a string vector std::vector<std::string> cities; you can add cities at the end with cities.pushback("New York"); and use cities[0] to get the data. | |
|
|
|