How to declare an array of strings in C ++?

In C ++, how can I declare an array of strings? I tried to declare it as an array char, but that was wrong.

+3
source share
3 answers
#include <string>

std::string my_strings[100];

This is C ++ using STL. In C, you would do it like this:

char * my_strings[100];

This reads as β€œmy lines are an array of 100 pointers to char” and the last as lines are represented in C.

+15
source

I would prefer to use a row vector in almost every case:

#include <string>
#include <vector>
std::vector<std::string> strings;
+13
source

Normal single line:

char foo[100] // foo is a 100 character string

You probably need:

char foobar[100][100] // foobar is a 100 member array of 100 character strings
0
source

Source: https://habr.com/ru/post/1707241/


All Articles