how to edit the input file

i have a text file which has a destination of some files. it is as below.

"E:\Feature\raw\new\frameSplit62.png"

i have many photos and i want a c++ code to change the image everytime i run the code.(loop).i only need to change the image number (62). from like 1- 100 for example.
please help
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>
#include <random>
#include <ctime>

std::string random_file_name()
{
    static std::string prefix = "E:\\Feature\\raw\\new\\frameSplit" ;
    static std::string suffix = ".png" ;

    static std::mt19937 rng( std::random_device{}() ) ;
    // static std::mt19937 rng( std::time(nullptr) ) ; // use this instead on MinGW

    static const int minv = 1 ;
    static const int maxv = 100 ;
    static std::uniform_int_distribution<int> distr( minv, maxv ) ;

    return prefix + std::to_string( distr(rng) ) + suffix ;
}

int main()
{
    for( int i = 0 ; i < 10 ; ++i )
        std::cout << "file name: " << random_file_name() << '\n' ;
}

http://coliru.stacked-crooked.com/a/2cf893e8455868a0
http://rextester.com/VBGHDS78495
thank you for this.this was a great help. can you tell me if i want to get the images in an order without taking random images what should i change
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>

std::string next_file_name()
{
    static std::string prefix = "E:\\Feature\\raw\\new\\frameSplit" ;
    static std::string suffix = ".png" ;
    
    static const int ub = 100 ; 
    static int n = 0 ;

    return prefix + std::to_string( n++ % ub + 1 ) + suffix ; // for 1 to hunfred
}

int main()
{
    for( int i = 0 ; i < 10 ; ++i )
        std::cout << "file name: " << next_file_name() << '\n' ;
}

http://coliru.stacked-crooked.com/a/6c9de02a17abe87f
Last edited on
this doesnt make a text file(.txt) and print the generated links right??
Last edited on
> this doesnt make a text file(.txt) and print the generated links right??

No it does not; it prints the generated file names to stdout.
To write them to a file, use an output file stream std::ofstream instead of std::cout.

There is an edit in the code posted earlier; it now generates file names with image numbers 1 to 100.
you have done a great help. thank you very much
@JLBorges can you help me to edit your code to give an txt file output.
Topic archived. No new replies allowed.