Append a string to each line in a file I wrote (several months ago) a program that will take an input file, with a provided std::string, and append that to each individual line in the file. Looking at the code again, I am wondering about the performance of this program, possibly if the file is very large or any of the lines/input string is long.

#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;

// argv[1] is input file name
// argv[2] is output file name
// argv[3] is string to add
int main(int argc, const char * argv[])
{
    if (argc != 4) {
        std::cout &lt;&lt; "Needs input file and string to add" &lt;&lt; std::endl;
        return EXIT_FAILURE;
    }
    std::ifstream in_file(argv[1]);
    std::string str;
    std::vector&lt;std::string&gt; vec, result_vec;
    while (std::getline(in_file, str)) {
        vec.push_back(str);
    }

    std::for_each(vec.begin(), vec.end(), [&amp;](std::string str) {
        result_vec.push_back(str + argv[3]);
    });

    std::ofstream out_file(argv[2]);
    std::copy(result_vec.begin(), result_vec.end(), std::ostream_iterator&lt;std::string&gt;(out_file, "\n"));
}
There is no need to store all lines from the input file in memory.
For each line read from the input you can append the string and write the 
result to the output file. This would save memory for large input files.

You should also check if opening the input and output file was
successful, otherwise your program will silently do nothing if the
files could not be opened/created.

std::ifstream in_file(argv[1]);
if (!in_file) {
    std::cerr &lt;&lt; "Could not open input file\n";
    return EXIT_FAILURE;
}
std::ofstream out_file(argv[2]);
if (!out_file) {
    std::cerr &lt;&lt; "Could not create output file\n";
    return EXIT_FAILURE;
}
const char * add_string = argv[3];

std::string str;
while (std::getline(in_file, str)) {
    out_file &lt;&lt; str &lt;&lt; add_string &lt;&lt; "\n";
}