When I'm trying to concatenate two strings the second string is replacing the first letters of the first string.
I'm using the getline function to get my input from a file, regex on the line to pick out the "UIN" of 9 digits, and trying to append another string onto the original, full line. Ex:
string line; ifstream in(infile); ofstream out("output.csv"); getline(in, line); regex pat("(\\d{9})"); smatch matches; if(regex_search(line, matches, pat)) { line += ",65"; cout<<line<<endl; out<<line<<endl; } (of course Im doing other things in this statement but none operate on the string line so I left it out)
The original line is
Alfonso Livingston,[email protected],800000092 And returned is
,65onso Livingston,[email protected],800000092 I saw this link and have tried creating new strings i.e.string newline(line); and doing string casts(?) (line += string(",65")) but it all ends with the same results. I have also tried to use the append function and the push_back function. Any help would be much appreciated!
edit:
This is my entire function. The input is coming from a comma seperated value list, input.csv. I really cannot replicate this outside of this function, so I don't know if I can give a complete verifiable example.
void combine(string infile) { ifstream in(infile); ofstream out("output.csv"); int size = getSize(infile); int hashVal; string line; string listVals; getline(in, line); regex pat("(\\d{9})"); smatch matches; if(regex_search(line, matches, pat)) { hashVal = hash(stoi(matches[0])); listVals = table[hashVal].getFirst()->getElem(); line += ",65"; cout<<line<<endl; out<<line<<endl; } } This isn't what the entire completed function is suppposed to do, but it's where I've had to stop to figure out this issue.
if.,65, except, when the string get printed, the extra carriage return character messes up the output.