Zahlen aus String extrahieren
-
Hallo,
habe ein Problem. Möchte aus einem String der wie folgt aufgebaut ist:
2 2 1.8 4.13 2.99 0.09 1 die Zahlen in ein Array schreiben. Leider habe ich keinen großen Dunst von regulären Ausdrücken.Falls es überhaupt damit funktioniert.
Vielleicht hat ja hier jemand eine Lösung für dieses Problem. Das wäre Super!
-
es sollte auch diese Zahlen aus dem String extrahieren :
4 2 -2.69 15.29 0.99 0.09 3
-
char numbers[] = "2 2 1.8 -4.13 2.99 0.09 1"; char numBuf[20] = {0}; vector<double> doubleVec; for(int i = 0, iMax = strlen(numbers), lastBlank = 0; i < iMax; ++i) { if(numbers[i] == ' ') { for(int j = lastBlank; j < i; ++j) { numBuf[j - lastBlank] = numbers[j]; } doubleVec.push_back(atof(numBuf)); for(int j = lastBlank; j < i; ++j) { numBuf[j - lastBlank] = 0; } lastBlank = i; } }
-
hab noch was gefunden hier im Forum:
#include <sstream>...
std::istringstream parser("1.23 4.56 7.89");
double x, y, z;parser >> x >> y >> z;
-
pulsedrone schrieb:
hab noch was gefunden hier im Forum:
#include <sstream>...
std::istringstream parser("1.23 4.56 7.89");
double x, y, z;parser >> x >> y >> z;
Nimm dies! oha! veräppelt dich bloß.