mardi 4 août 2015

Strange characters using std :: cin

I have been developing an application in C++ with Xcode 6.3.2 under OSX Yosemite and whenever I ask the operator to enter a parameter with the code below, it works fine, except if at some point the operator makes a mistake while typing and corrects his entry using the arrows on the keyboard. If he does so, this is the output he gets :

Please enter the name of the object : test
You entered : test

Here is the code :

#include <iostream>
using namespace std;

int main( int argc, char** argv )
{
    char *object_name = new char [20];
    cout << "\nPlease enter the name of the object : ";
    cin >> object_name;
    cout << "You entered : " << object_name;
}

How could I get rid of those characters ?

Thank you.

Aucun commentaire:

Enregistrer un commentaire