hello again,
so i want to make a programme
where the file saved is saved with different names at every loop..
like at first loop it will save as file1.txt, 2nd loop file2.txt, so on...
so this is my code...

#include <iostream>
#include <fstream>

using namespace std;

int main()
    int x = 0;
    cout << "Hi" << endl;
    for (x == 0; x<10; x++){
        fstream file;
        file.open("trial", ios::out);
        file<<"save it";

    cout<<" DONE";
    return 0;

so this is what the code is, it will loop 10 times and it will save it as file1.txt, file2.txt, file3.txt......... file10.txt

please help, thanks

You need to open the file with a new name each time:

for (int x = 0; x < 10; x++)
    stringstream filename;

    filename << "trial" << (x + 1) << ".txt";

    ofstream out(filename.str().c_str());

    out << "save it";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.