Search
 
SCRIPT & CODE EXAMPLE
 

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 
    }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Marin and Photoshoot codeforces solution in c++ 
Cpp :: leetcode 36 c++ 
Cpp :: draw point sfml 
Cpp :: generate consecutive numbers at compile time 
Cpp :: ue4 array copy c++ 
Cpp :: Character convert c++ 
Cpp :: python Difference Array | Range update query in O(1) 
Cpp :: c pointer syntax 
Cpp :: convert c++ to python online 
Cpp :: C++ Dynamic allocation failing 
Cpp :: 1491. Average Salary Excluding the Minimum and Maximum Salary leetcode solution in c++ 
Cpp :: the partition function of a system is given by z= 1/(1-e^-bEi), calculate the total energy of the system 
Cpp :: assert warning c++ 
Cpp :: ue4 log 
Cpp :: sort 3 numbers using swap cpp 
Cpp :: convert c++ code to exe 
Cpp :: Structure of s void function 
Cpp :: const char * to std::wstring 
Cpp :: patterns in c++ 
Cpp :: hello command not printing in c++ 
Cpp :: c++ max 
Cpp :: c++ multi-dimensional arrays 
Cpp :: c++ variables 
Cpp :: c++ new operator 
Cpp :: accumulate in c++ 
Cpp :: make an x using asterisk c++ 
C :: What are the 3 basic types of Plate Boundaries? Explain their differences (how they act). 
C :: Donut-shaped C code 
C :: if statement shorthand c 
C :: size of an array c 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =