Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to figure out how to make simple console program that simply reads from simple text files that can be expanded. It paints a menu to the console like a batch file


Select 1) Enter name/string to first file
Select 2) Enter name/string to 2nd file
Select 3) Enter name/string to 3rd file
Select 4) Enter name/string to 3rd file

Select X) add file option to menu (aka add another file)

Selet X) Combine names in all possible combinations from file1/file2 (this can be a command line argument), since the input would be the text file names and it would just read down the list and output a CSV/Text file with all possible combinations of words.

Names1.txt, names2txt, etc.

I've found some code on the web that kinda does something heading in the direction but not sure how to modify it, it just randomly selects from a distribution, but the code appears pretty solid.

Basically I just want to input words into seperate files from the command console from the menu and then run an algorithm that can combine any combination of word from any combination of file.

Say there were two files with 4 words in each, or 5 files with 5 words in each and the algo would just tick down the file and

combine each word from each column them all in a list with a space and output it to a text file.

Red, blue
sally, Mod

New file:
red blue
red mod
sally blue
sally mod
blue red
blue sally
mod red
mod sally

Hope this helps. Basically just making a simple "X" name generator that can be expanded (aka you can use it for anything, and you just have files named XX_item to organize the words input from the console. So you you aren't tied to a specific input.

What I have tried:


std::vector read_names(const char* filename)
std::ifstream in{ filename };
std::vector names;

std::string name;
while (getline(in, name))
if (!name.empty())

return names;

int main()
const auto first_names = read_names("firstnames.txt");
const auto last_names = read_names("lastnames.txt");

std::mt19937 rng{ std::random_device{}() };
std::uniform_int_distribution first_dist{ 0, first_names.size() - 1 };
std::uniform_int_distribution last_dist{ 0, last_names.size() - 1 };

return 0;

Updated 30-Jul-23 4:33am

1 solution

Have a look here: Combinations in C++[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900