Thursday 15 August 2013

c++ - Append extension to a string passed by reference -



c++ - Append extension to a string passed by reference -

in code, next i.e. pass name of string becomes filename write to, when string name passed reference, unable utilize + operator overloading append *.txt filename, same code shown below:

void myfunction (string &filename){ (1) filename += ".txt"; fstream file; file.open(filename, iostream::out); }

vs2012 intellisense shows error @ += saying "no operator matches these operands" tried passing adding, mean += operator can't used on string names passed reference. @ to the lowest degree thats understand.

but when re-create filename reference string , utilize that, produces file without name i.e. .txt file.

string myname = filename; filename += ".txt"; @ (1)

the file produced without name. thought have gone wrong?

c++ file visual-studio-2012

No comments:

Post a Comment