Pergunta

I am very new to MFC and now I want to convert Exponential Numbers "4.246E+3" into 4246.

Input is in string and output I want to get it in int.

Please let me know if we have any way(API) to get it in MFC, C++.

Thanks MAP

Foi útil?

Solução

Following code will work fine to solve your problem...

#include<sstream>

string str = "4.246e+3";
stringstream ss;
double number;
ss<<str;
ss>>number;

Outras dicas

You can the standard library function which allows for str to be in scientific notation.

int stoi (const string&  str, size_t* idx = 0, int base = 10);

If you supply idx and it comes back nullptr then str was a pure number, if not then it returns the address of the first invalid character in str.

It's better to use the standard C++ library functions rather than MFC whenever possible to assist in any future porting out of MFC.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top