Hi, I'm really quite new to C++ but I'm trying to code a unit converter for a class assignment.
I'm stuck on trying to read an empty space before a character within a string.
For example, if I'm trying to convert from 'km' to interpret the k part, I use the following;
1 2 3 4 5 6 7 8 9
|
string UnitFROM;
double y,CC;
if (UnitFROM.at(found-1)=='k')
{
cout << "found kilo metre"<<endl;
CC = y * 1e3;
}
| |
So in the above I can interpret 'km' and do something when this occurs, it works successfully, however when the initial unit is 'm' and I try a similar method, where I search for ==' ', it doesn't work. I've tried =='NULL' , ==NULL, ==empty() all with no avail.
I am at my wits end! I have a back up option where I measure the string length, and when it equals 1, and the one character within the string is == m I carry out a function, but this doesn't work either;
1 2 3 4 5 6 7
|
if (UnitFROM.at(found) == 'm' && UnitFROM.length() == 1)
{
cout << "found metre"<<endl;
//if (int(found)>0)
CC = y * 1;
}
| |
Any suggestions or pointers would be greatly appreciated.
thanks!