Jump to content
Bernardo Vieira

string com mesmo nome, divididas por parametros

Recommended Posts

Bernardo Vieira

bom, basicamente eu queria usar o mesmo nome de variavel para com parametro...nao perceberam nada, pronto, vou tentar explicar melhor

por exemplo, eu tenho esse codigo

#include <iostream>

using namespace std;

int main() {
char *espaco = new char[256];

espaco = "ola!";
cout << espaco << endl;
espaco = "again";
cout << espaco << endl;

system("pause");
return 1;
}

mas se fosse para usar string, teria por exemplo

std::string frase = "ola mundo";

sera que tem uma forma de fazer tipo

std::string frase[0] = "ola mundo";
std::string frase[1] = "ola mundo";
std::string frase[2] = "ola mundo";

tentei de varias formas, tentei com o char *espaco, (achei isso num tutorial de alocacao dinamica de memoria, que por acaso eu estava a aprender) masnao resultou em nada, nao tenho menor ideia de como fazer

pensei em usar char frase [numero_de_frases][caracteres_por_frase] mas cheguei a pensar que nao ficaria grande coisa. Podem ajudar-me?

Share this post


Link to post
Share on other sites
KTachyon
string frase[3];

frase[0] = "ola mundo";
frase[1] = "ola mundo";
frase[2] = "ola mundo";

  • Vote 1

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
Bernardo Vieira

quase podia jurar que ja tinha tentado isso! mas certamente nao, mas foi algo bem parecido!

Muito obrigado :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.