c++windowsclioncout

How to place a space at the end of cout


I need to know why c++ doesn't see the space just at the end of cout function. I'm using CLion and C++ 23 (language_standart)

int main()

{

    string Item ;
    double Price ;
    int Quantity ;
    double Total ;

    cout << "Your item to buy : " ;
    getline(cin, Item) ;
    cout << "Price of the item : " ;
    cin >> Price ;
    cout << "Quantity of the item : " ;
    cin >> Quantity ;

    cout << endl ;

    Total = Price * Quantity ;

    cout << "Item : " << Item << endl ;
    cout << "Price : " << Price << endl ;
    cout << "Quantity : " << Quantity << endl ;
    cout << "Total is : " << Total << endl ;

}

When I run the code, it returns me

Your item to buy :**HereIsNoSpace**
**HereIsSpace**Price of the item : 
**HereIsSpace**Quantity of the item :

So I need to enter an Item just after ":" and not ": "

And as you can see probably my spaces somehow goes just after my input and passes to the next string


Solution

  • Apparently one of the workarounds is, try doing the following: in Registry (Help | Find Action..., type Registry there) disable the run.processes.with.pty option and restart CLion. Does that help? According to the response in CPP-12752 disabling PTY (without CLion restart, since the run.processes.with.pty option is not saved after CLion's restart - CPP-8395) helps.

    Guys I've found the solve of this heck !