我不知道这里发生了什么事。我将两个字符串转换为双精度值,第一个字符串总是经过,但第二个字符串没有,并且切换它们的方式并不重要! 下面的代码:帮助转换字符串加倍?
#include <iostream>
#include <math.h>
#include <string>
#include <sstream>
using namespace std;
int main() {
string temp;
double ax,bx,cx,ay,by,cy;
cout << "Enter x and y for point 1 (separated by a comma)";
cin >> temp;
int where=temp.find(",");
int hmm=temp.length()-where;
cout << hmm << endl << where << endl;
cin.get();
stringstream ss;
string stAx,stAy;
stAx= (temp.substr(0,where));stAy = (temp.substr(where+1, hmm-1));
ss << stAx;ss >> ax;
ss << stAy;ss >> ay;
cout << "Ax: " << ax << endl;
cout << "Ay: " << ay << endl;
system("pause");
return 0;
}
任何人都可以找出我做错了吗?
在此先感谢!
看来你的代码的一部分丢失,所以我有猜测你的问题是什么。但你有没有看过boost :: lexical_cast()呢? – Axel 2010-12-22 19:09:32