How to take line break in the "Cin" of the <iostream> library?

Asked

Viewed 949 times

3

How can I take the line break when reading some variable with cin?

#include <iostream>
using namespace std;

int main()
{
    int dia, mes, ano;
    cout<< "Data: ";
    cin>> dia;cout<<"/";  cin>> mes;cout<<"/";  cin>> ano;
    system("pause");
    return 0;
}

Compiled: Resultado

I want it to stay that way: Como deve ser

  • It would be interesting to post the code instead of the code image. So you increase the interest of people to help you.

  • Put this code in place of the FIRST image.

  • It’s perfect! It’ll be easier for someone to help you now.

  • ready, I just want when the "Cin" reads the value not skip a line or is continue in the same line

  • Avoid line breaking with cin is not possible. Or it is all like a string and parses each part of the date or implements a read based on getch

1 answer

3


It is not possible. The cin is made for basic use, for experimentation, minimal interaction without ceremony. If you want to have total control over the data entry you will have to write a code that does the control the way you want, which is not simple to do right. C++ is not a ready-to-use language, and it’s rare to have external libraries that aren’t too generic.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.