How?? very simple question C++

How do I put the input between<angle brackets>?
I wanna see like that..after prompt the user to enter the input..
How many miles round-trip a day do you commute? <22>

cout<<"How many miles round trip a day do you commute?";
cin>>miles;

????? how

You can't do this with just standard C++; the user will have to press enter to complete their input, so even if you just tried to put > at the end it would not work properly. You'll need to either use system-specific commands or get a console library.
..
Last edited on
If you need to put <> around your input, then read it as a string:

1
2
3
4
5
6
7
8
9
10
11
12
13
std::string input;
std::cin >> input;
float number;

if (input[0] == '<')
{
    // string number is the number only.
    string number = (input.begin()+1, input.find_last_of('>')-1;

    // Now let's format it to a number: 
    stringstream iss(number);
    iss >> number;
}
Last edited on
I didnt get anything, can you type just these part into his code?
That's a strange request. You want me to put a generic solution into someone else's specific code. You must have the same assignment.

Everywhere that he has cin>> replace that with a function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void get_input(float &number)
{
    std::string input;
    std::cin >> input;

    if (input[0] == '<')
    {
        // string number is the number only.
        string number = (input.begin()+1, input.find_last_of('>')-1);

        // Now let's format it to a number: 
        stringstream iss(number);
        iss >> number;
    }
}
Last edited on
I'm pretty sure the project is just stating for clarity that the number in the brackets is the number that has been input for the example.

I don't think this program actually requires the inputs to be enclosed in brackets.

Seems pretty clear from the note.
What is the question, do you want the number to be enclosed in brackets after you cin it, or do you want the user to see it like they are typing into the area between the brackets?
Topic archived. No new replies allowed.