这里是我到目前为止的代码:如何将字符串转换为C++中的整数?
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
string exp;
cout << "Enter a number and raise it to a power" << endl;
cin >> exp;
int num = exp[0];
int pow = exp[2];
cin.get();
cin.ignore(256,'\n');
}
基本上,我试图让一个程序,你可以输入类似“2^5”,它会为您解决。到目前为止,我已经取得了字符串的第一个和第三个值,并将它们称为“num”和“pow”。 (数量,功率)如果您尝试类似“cout < <”;“它会给你十进制的Ascii值。我如何将它转换为小数?
或使用'的std :: Stoi旅馆()'函数:'N =标准:: Stoi旅馆(exp.substr(0,POS));' – bames53 2012-04-22 19:03:01