Back Button
Back to Chapter
C++ Introduction
No items found.
C++ Basics
No items found.
C++ Control Statements
No items found.
C++ Logical Operators
No items found.
C++ Procedural Programming
No items found.
C++ Structural Programming
No items found.
C++ Implementation of OOPS
No items found.
C++ Arrays and Vectors
No items found.
C++ Error Handling
No items found.
C++ File Handling
No items found.
Collapse_Icon
Table of Contents

Create a file to store the data of a student in a file and close the file. Make use of structures and store this data in a file names new_filewrite.

Solution:

#include using namespace std; struct student{ char name[20]; char course[20]; int rollNo; }; main() { student a; cout<<"enter the name:"; cin>>a.name; cout<<"/nEnter course:"; cin>>a.course; cout<<"/nenter rollno:"; cin>>a.rollNo; fstream newFile; newFile.open("new_filewrite.txt",ios::out); if(!newFile) { cout<<"File creation failed"; } else { cout<<"New file created"; newFile<<"NAME:"<
https://s3-us-west-2.amazonaws.com/secure.notion-static.com/463950ba-e072-48da-8151-d0fc4e10e817/Untitled.png

Output: New file created