0

I am trying to combine Strings and Int to find a file, but I am trying to see if a save file exists, I don't know why it won't work here is the code, file.open("Save" + saveNum + ".dat");

I expected the code to combine the strings and int, the result was an error.

  • C++ doesn't support this, you need to convert your number to a string manually by eg using `std::to_string` – Alan Birtles Jun 05 '23 at 05:58
  • For C++20 use `auto filename = std::format("Save{}.dat",saveNum); file.open(filename);` pre C++20, use the [fmt library](https://github.com/fmtlib/fmt). Or you can use [std::ostrstream](https://en.cppreference.com/w/cpp/io/ostrstream) as an intermediate step. `std::ostrstream os; os << "Save" << saveNum << ".dat"; file.open(os.str());` – Pepijn Kramer Jun 05 '23 at 06:00

0 Answers0