문제

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.

도움이 되었습니까?

해결책 2

string path = "./Questions/" + to_string(randomID) + ".quiz";

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top