string in int konvertieren
-
Hallo,
ich weiß zwar, das es schon öfters angesprochen worden war, aber trotzdem bekomme ich das nicht hin.
was mach ich falsch??#include "stdafx.h" #include <string> #include <iostream> #include "stdio.h" using namespace std; void main(void) { string s="5"; int zahl =atoi(s); cout<< zahl<<endl; }
-
#include <string> #include <iostream> #include <strstream> using namespace std; int main(void) { string s="5"; istrstream a(s.c_str()); int zahl; a >> zahl; cout<< zahl<<endl; }
-
Hallo,
atoi erwartet einen const char*, keinen std::string. Es muss also heißen:int zahl =atoi(s.c_str());http://www.c-plusplus.net/forum/viewtopic-var-t-is-39488.html
-
Vielen Dank an euch!!!