std::ifstream text(how to change this);

Hello!

std::ifstream text( "./text1.txt" );

How do I change "text" to something else like "./text55.txt" ?
Like with a variable?
You can build the file name using a stringstream
eg:
1
2
3
4
5
std::stringstream ss; // requires header <sstream>
int number = 55;
ss << "./text" << number << ".txt";

ss.str().c_str(); // will return the C string with the contents if the stream, you can use it as argument to ifstream constructor 
Topic archived. No new replies allowed.