How do I store a string in a char array in c ++?

0

My problem is that I capture 2 strings and then I want to save them in their arrangements

string nombre_buscado;
string apellido_buscado;

a

nombre[5][10]
apellido[5][10]

and I get the error in:

nombre[i]=nombre_buscado;
apellido[i]=apellido_buscado;

Thanks in advance.

    
asked by Pedro Robles 27.09.2017 в 03:53
source

2 answers

1

What I see is that name [i] = searchname you need the location this would look like this: name [i] = searchname [i] and this goes inside a for so you can pass all the locations.

#include <string>
#include <iostream>

using namespace std;

int main()
{
string mensaje, otroMensaje[10];
int i;

mensaje = "Pedrito";
for(i=0;i<7; i++){
    otroMensaje[i] = mensaje[i];
}

cout << endl;
for(i=0;i<7; i++){
    cout << otroMensaje[i];
}
return 0;
}
    
answered by 27.09.2017 / 05:37
source
0

You have to take into account that you are creating two-dimensional arrangements, so to store values in them, you have to indicate the positions where you will store them.

nombre[5][10]

nombre is a bi-dimensional array of 5 rows and 10 columns, if you want to store a value in that array you have to indicate the position of the row and the column where the value will be stored.

nombre[2][5] = nombre_buscado;

In this case, the value of the variable nombre_buscando will be stored in row 3 and column 4. In the arrangements the positions start counting from zero. If you have a 3-position arrangement, the positions will be: 0, 1 and 2.

    
answered by 27.09.2017 в 05:34