How to pass string as a parameter in C ++

0

Oops, people, easy?

Next, programming teacher passed a little project and I need to pass a string as a parameter in C ++. How do I do? I've seen it on the internet and none of the ways worked.

I tested it like this:

void text_to_morse(std::string *frase, int tamanho);

So:

void text_to_morse(string& frase, int tamanho);

So:

void text_to_morse(char frase[], int tamanho);

So:

void text_to_morse(const char* frase, int tamanho);

And so:

void text_to_morse(const std::string &frase, int tamanho);

How to do it, after all? The function will translate a phrase that the user typed into morse code and save to a file.

    
asked by anonymous 10.04.2017 / 01:57

1 answer

1

You should do the c ++ style, in which you do not need the size parameter, just call the size () method to get the string size. And in the end return the string after the conversion.

std::string text_to_morse(std::string frase){
     //converte a string frase
     return frase;
}
    
10.04.2017 / 17:21