I'm just writing a little script to create some fake discord names.
To do this, I took a couple of .csv files with adjectives and nouns, imported them into vectors, and concatenated them. Ex:
vector<string> noun; vector<string> adj; infile.open("english-adjectives.txt"); while(infile.good()){ getline(infile,x); adj.push_back(x); } infile.close(); shuffle(begin(adj), end(adj), rng); I did the same thing for nouns, and then tried to concatenate them with a number, but I got a really weird result.
for (unsigned int i = 0; i < adj.size(); i++){ string temp; temp.append(adj[i]); temp.append(noun[i]); discord.push_back(temp); } for (unsigned int i = 0; i < discord.size(); i++){ cout << discord[i] << "#0001" << "\n"; } output:
#0001icresearch #0001downstairs #0001edfiddle When I remove the "#0001" part, it prints just fine.
honoredfiddle wanderby deliciousofficial Any ideas on why this is happening? I checked the newline chars in all my .csv files, and it's formatted for Unix, so I have no idea why this is happening.
while(infile.good()){ getline(infile,x); adj.push_back(x); }Test for valid stream, read from stream, store in container regardless of whether or not read from stream succeeded. You need to read, then test, not test then read.while(getline(infile,x)) { adj.push_back(x); }\r\n). But the computer you are running this on uses UNIX style line endings (\n) so each line in the CSV has a\rat the end that is not being removed as your program reads it. A\rmoves the cursor to the left edge of the current line, so the number overwrites the name. There are multiple ways of removing the\rfrom the CSV file - or you could even do it inside this program after reading the data. One possible way: stackoverflow.com/questions/2528995/remove-r-from-a-string-in-cnounhas the identical number of elements asadj, which is a gaping hole in this methodology. if there are fewer adjectives than nouns, it will "work". If there are more, this is a recipe for undefined behavior.