Home

Published

- 1 min read

write variable to file cpp

img of write variable to file cpp

The solution for this is noted below

write variable to file cpp

Solution

   int main()
{
    char name[20], phone[20];

    cout<< "Enter your name: ";
    cin>> name;
    cout<< "Enter you phone number: ";
    cin>> phone;

    ofstream file_w ("test.txt");

    file_w << name <<endl
           << phone<<endl;

    cout << "Process complete";
    file_w.close();

    return 0;
}

Try other methods by searching on the site. That is if this doesn’t work