Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

how to open and print in a file in c++

// this is how to make function that you pass vector of strings, and it prints 
// all strings that are in that vector in a certain file
#include <bits/stdc++.h>
using namespace std;

void Print_File (vector<string> v,string FileName){
    ofstream outfile;
    outfile.open(FileName);
    for(int i = 0; i < v.size(); i++){
        outfile << v[i] << " ";
    }
    outfile.close();
    return;
}
int main(){
  vector<string> v = {"my","name","is","jeff"};
  Print_File(v,"TextFileName.txt");
}
 
PREVIOUS NEXT
Tagged: #open #print #file
ADD COMMENT
Topic
Name
7+6 =