Sam Sam - 1 month ago 6x
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!


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;