in c++
Write a function that:
#include<iostream>
#include<fstream>
using namespace std;
//method to write the integer into file
int Write(string str,int n)
{
ofstream outFile;//declare file object
outFile.open(str.c_str());//open the file
if(!outFile) //condition for unable to open the
file
return -1;//return -1
outFile<<n;//write n into file
outFile.close();//close the file
return 0;//return 0
}
//driver code
int main()
{
string str = "WriteData.txt";//initialize the string
variable by a name of file
int n=14;//initialize n
//call to Write()
Write(str,n);
}
OUTPUT
Get Answers For Free
Most questions answered within 1 hours.