Search
 
SCRIPT & CODE EXAMPLE
 

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");
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: setw in c++ 
Cpp :: c++ find largest number in array 
Cpp :: comment in c++ 
Cpp :: c++ print every element in array 
Cpp :: how to write a hello world program in c++ 
Cpp :: minimum and maximum value of a vector in C++ 
Cpp :: how to loop a 2 dimensional vector in c++ starting from second element 
Cpp :: c++ check if string contains uppercase 
Cpp :: replace komma with space C++ 
Cpp :: how to make a c++ program which takes two integers and calculate average 
Cpp :: bit c++ 
Cpp :: how to run a c++ program in the background 
Cpp :: C++ Multi-line comments 
Cpp :: include spaces while reading strings in cpp 
Cpp :: factorial using recursion cpp 
Cpp :: calculator c++ 
Cpp :: change to lowercase in notepad++ 
Cpp :: time function c++ 
Cpp :: c++ count number of element in vector 
Cpp :: adding element in vector c++ 
Cpp :: print all elements of vector c++ 
Cpp :: string stream in c++ 
Cpp :: find primes in cpp 
Cpp :: initialize 2d vector 
Cpp :: concatenate string program in c++ 
Cpp :: c++ iterate over vector of pointers 
Cpp :: migration meaning 
Cpp :: indexing strings in c++ 
Cpp :: std::iomanip c++ 
Cpp :: c++ function default argument 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =