string path = "./Questions/" + to_string(randomID) + ".quiz";
C++ : String + integer path [duplicate]
Pregunta
I'm pretty new to C++, so sorry if I asked something obvious.
srand(time(NULL));
int randomID = (rand() % 100);
string path = "./Questions/" + randomID + ".quiz";
In /Questions there are .quiz Files that are named as random integer numbers like "1.quiz", "202.quiz", "13.quiz"
It doesn't work when I put the randomID in, how can I solve this?
The Error is in German so I don't think it will help you, it just says that ".quiz"
is wrong.
Solución 2
Otros consejos
random is an int there is no defined function string operator+(string,int)
. You could provide one, but I wouldn't suggest that. You can however convert the number to a string.
If you are using c++ 11 you can use to_string(int) if you are using c++03 stringstream is available
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow