Sam Sam - 1 year ago 122
C++ Question

Read in Dollar Amount (with dollar sign) C++

I need to read in a value (cin) including a dollar sign and a dollar amount, but I only want to read in the amount.

In other words, I have this input:
but I want to read in and store

The current approach I thought of was reading the value in as a string, removing the first character, and then converting to a double. But, I feel like this method is inefficient and there's a better method out there. Any tips? Thanks!

Answer Source

I agree with Magnus: this seems minor. But if you really want to do it, just read a character then read a double:

char ch;
double d;
std::cin >> ch >> d;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download