Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Removed redundant tag info from title
Link
Ken White
  • 126.2k
  • 15
  • 237
  • 476

Why is this string being overwritten instead of being concatenated? (c++)

Source Link
Pingu21
  • 181
  • 1
  • 4

Why is this string being overwritten instead of being concatenated? (c++)

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.