Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Use command line arguments to create file c++

#include <string>
#include <iostream>
#include <fstream>

int main(int argc, char** argv) {
    std::string text;

    for(int i = 1; i < argc; i++) {
        std::cout << "Enter your text: " << std::flush;
        // Read a line from standard input
        std::getline(std::cin, text);

        // Make the file
        std::ofstream file(argv[i]);
        // Write the text
        file << text << '
';
        // File gets closed automatically 
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Use #command #line #arguments #create #file
ADD COMMENT
Topic
Name
7+7 =