Answers for "c++ print tht file"

1

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");
}
Posted by: Guest on April-29-2022
0

print contents of cpp file

#include <iostream>
#include <fstream>

int main()
{
    std::ifstream f("file.txt");

    if (f.is_open())
        std::cout << f.rdbuf();
}
Posted by: Guest on October-21-2020

Code answers related to "TypeScript"

Browse Popular Code Answers by Language