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;
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.
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;
}
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;
}
}
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?