I have a feeling this isn't the standard standard library but rather a self-made one. You can try iterating directly, I'm using std::string_view to keep the copy operations to a minimum:
#include <iostream>
#include <map>
#include <string>
std::map<std::string_view, char> morse_code_table = {
{".-", 'A'}, {"-...", 'B'}, {"-.-.", 'C'}, {"-..", 'D'},
{".", 'E'}, {"..-.", 'F'}, {"--.", 'G'}, {"....", 'H'},
{"..", 'I'}, {".---", 'J'}, {"-.-", 'K'}, {".-..", 'L'},
{"--", 'M'}, {"-.", 'N'}, {"---", 'O'}, {".--.", 'P'},
{"--.-", 'Q'}, {".-.", 'R'}, {"...", 'S'}, {"-", 'T'},
{"..-", 'U'}, {"...-", 'V'}, {".--", 'W'}, {"-..-", 'X'},
{"-.--", 'Y'}, {"--..", 'Z'}, {"-----", '0'}, {".----", '1'},
{"..---", '2'}, {"...--", '3'}, {"....-", '4'}, {".....", '5'},
{"-....", '6'}, {"--...", '7'}, {"---..", '8'}, {"----.", '9'},
{".-.-.-", '.'}, {"--..--", ','}, {"..--..", '?'}, {"-....-", '-'},
{"-.--.", '('}, {"-.--.-", ')'}, {"---...", ':'}, {"-.-.-.", ';'},
{"-..-.", '/'}, {"-...-", '='}, {".-.-.", '+'}, {"..--.-", '_'},
{".----.", ' '}, {"-.-.--", '!'}, {"-.-.-.", '&'}, {".-...", '&'},
{"-..-.", '\"'}, {"..--.-", '@'}, {"|", ' '}};
char decode_symbol(const std::string_view &symbol) {
if (morse_code_table.find(symbol) != morse_code_table.end()) {
return morse_code_table.at(symbol);
} else {
return '!';
}
}
std::string decode_morse(const std::string &morse) {
int current_start = 0;
std::string decoded = "";
for (int i = 0; i <= morse.size(); i++) {
if (i == morse.size() || morse.at(i) == '|') {
decoded += decode_symbol(morse.substr(current_start, i - current_start));
current_start = i+1;
}
}
return decoded;
}
int main() {
std::string a;
std::cin >> a;
std::cout << decode_morse(a);
}