0

I have an array of strings called peliculas:

        string peliculas[10][4];

and I have a tamanopeli that is a number. This number tells me in which position the new pelicula will be added. But the problem is that I need the user to be able to write a data with space. But if the user intends to write "fast and fourious", then the program save it as

peliculas[tamanopeli][0]= fast
peliculas[tamanopeli][1]= and
peliculas[tamanopeli][2]= fourius

and I need

peliculas[tamanopeli][0] = fast and fourius

because "fast and fourius" is only 1 string

                 cout<<"wtite the name of the movie: ";
                 cin>>peliculas[tamanopeli][0];

                 cout<<"\nwrite the gender: ";
                 cin>>peliculas[tamanopeli][1];

                 cout<<"\nwrite first date: ";
                 cin>>peliculas[tamanopeli][2];

                 cout<<"\n write last date: ";
                 cin>>peliculas[tamanopeli][3];
fvrghl
  • 3,642
  • 5
  • 28
  • 36

3 Answers3

1

You need to use std::getline:

getline( cin, peliculas[tamanopeli][0] );
paddy
  • 60,864
  • 6
  • 61
  • 103
1

So, I think what you needed is just the cin.getline(), which can read a string with the space. It's can get a whole line of string~

FusionXu
  • 11
  • 2
0

You are using cin to collect data. cin stops reading at the first whitespace. Instead use getline()

#include <iostream>
#include <string>

using namespace std;

int main()
{
string input;
getline(cin, input);

cout << "You entered: " << input << endl;
}