Read File Char by Char C++ Get Random Values
random character generate
im writing a program to aid me empathize on rand fucntion i dont get how to utilize it with a file that has a bunch of characters i recollect i would accept to do it in a loop so information technology could exist random and set srand (fourth dimension(Naught));
| |
hither is my file
4
ABC
Abc
AbC
aBC
i got it random generate but i want to take hold of a just one line not all the lines
| |
Last edited on
empathise on rand fucntion
past all means practise so but the most upward-to-engagement way of generating random numbers in C++ is using the <random> library - search this forum for several examples final few weeks
use std::getline() to read the file by line into std::string, salve the lines in a std::vector<std::string>, std::random_shuffle the vector and pick-off any particular element similar vec[0], etc
i dont empathize what you mean
"use std::getline() to read the file by line into std::string, save the lines in a std::vector<std::cord>, std::random_shuffle the vector and pick-off any particular chemical element like vec[0], etc "
i want to employ rand() not the library
the things is i have character not numbers
| |
http://coliru.stacked-kleptomaniacal.com/a/8d76660426f8b27e
i have graphic symbol not numbers
who said anything about numbers?
why when it'due south not the most accurate option bachelor unless your professor insists
i just want to exist able to but to employ rand() srand(time(nothing))
cheers for the case @jlborgers
since it a cord could i practise it with a character
Concluding edited on
If C-fashion arrays must be used:
| |
http://coliru.stacked-crooked.com/a/4574c133474cd9bc
Topic archived. No new replies immune.
Source: https://www.cplusplus.com/forum/general/210722/
0 Response to "Read File Char by Char C++ Get Random Values"
Post a Comment