Hey everyone, still learning c++ I had a question.

How do I create an array that will hold strings of text.

such as:

??? map[10];
map[1]= "text";
map[2] = "text2";
map[10] = "text3";
cout<< map[1] "\n";

help would be great
ink

Hey everyone, still learning c++ I had a question.

How do I create an array that will hold strings of text.

such as:

??? map[10];
map[1]= "text";
map[2] = "text2";
map[10] = "text3";
cout<< map[1] "\n";

help would be great
ink

You can do it in many different ways,
but I think c++ fanatics recommends using stl vector,
theres a little example here.

http://www.codersource.net/c++_vector_stl.html .

But i would just do

#include <iostream>
#include <string>

using namespace std;
int main(){
  string array[10];

  array[0] = "element1";
  array[1] = "element2";

  cout << array[0] <<endl;
}

Hope it helps

As monkey_king points out there is a variety of options. Your question is similar to asking "How do I make cookies?" In order to best answer your question we need more input or make our best guess as to what you need/want/know.

Do you know there are multiple types of strings? If so, which type are you planning to use?

If you're not using STL strings do you know how to manipulate C style strings using functions like strcmp(), strcopy(), etc?

Do you know about STL classes such as vector and string? If so they can make programming easier by handling a bunch of tasks for you. If not, so be it. You can still write valid, portable code without using them.

If you are using C style strings do you know about multidimensional arrays?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.