Help Changing Array Of Characters To A String Array

I have an array titled: char TypeOfSong[arraySize] where the array size is 15. I am reading data from a file into this array and the characters can be either 'C', 'D', 'E', or 'R'. Each of these characters stands for a word (sting) and when I output the array, I need the strings to show up, not the characters. I have been reading online and in my book but I can only find information on turning one array with the same characters into a string. How would I go about changing this character array with different characters into a sting?

The characters stand for:

C = Country
D = Dance Party
E = Elevator
R = Rock

Any pointers would be helpful.
Thank you, I really appreciate it!
I think that container std::map<char, std::string> is more suitable in this case.
Last edited on
It is more suitable. But I am still having trouble with the concept of how to change those individual characters into the titles that I have listed above.
In this case I do not understand why you wrote that "it is more suitable"? Or do you always write what you do not understand?
Okay, I do not exactly understand what std::map<char, std::string> would do. Could you please explain that to me?
It will contain pairs

'C', std::string( "Country" )
'D'. std::string( "Dance Party" )
'E', std::string( "Elevator" )
'R', std::string( "Rock" )

It is even better to have std::map<char, const char *>

To understand basic ideas behind std::map try the following example for example at www.ideone com

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <map>
 
int main()
{
    std::map<char, const char *> m = 
    { 
        { 'C', "Country" },
        { 'D', "Dance Party" },
        { 'E', "Elevator" }, 
        { 'R', "Rock" }
    };
    
    std::cout << m['C'] << ' ' << m['D'] << ' ' << m['E'] << ' ' << m['R'] << std::endl;

    return 0;
}
Last edited on
Topic archived. No new replies allowed.