If there’s a built in way to generate random strings in C++, then I don’t know about it, but here’s basically how I would go about doing it manually. I also don’t know your level of programming proficiency so let me know if I need to explain any of these bullets further.
- There is a library called random (I believe, my peak in C was awhile ago and I haven’t worked with ++ much at all) for generating random numbers.
– Is the desired length of strings known or should that be random too? I’d start by generating string lengths if that also needs to be generated.
– Allocate the memory necessary for that number of chars. Unless C++ has better string handling than C, keep in mind that this will be an array of character arrays….less than ideal.
– For each string, again generate random numbers. If you only want letters a-z and A-Z then generate numbers from 65–90 and 97–122. You can then cast these integers to char and it will convert them to the character in the ASCII table that corresponds to the number. See ASCII table here: http://www.asciitable.com/. Obviously if you want numerals or punctuation to be available you’ll have to alter your ranges as needed
– Ta da. To display, iterate through the array and use printf.