High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
oops (1).pptx
1. CSV FILE
MANAGEMENT IN C++
CSV FILE MANAGEMENT USING C++
Presented by :-
Aryan Rai (111048)
Nikhil Kumar (111076)
Shivam Chapke (111084)
2. CONTENT
• What Is A CSV File ?
• Features Of CSV File
• Uses Of A CSV File
• File Functions In C++
• Modes Of Opening A File In
C++
• CSV File Operations
• Errors And Exceptions When
Reading Or Writing To A
CSV File
3. What Is A CSV File ?
CSV is a simple file format used to store
tabular data such as a spreadsheet or a
database.
CSV stands for Comma Separated Values.
The data fields in a CSV file are
separated/delimited by a comma (‘, ‘).
The individual rows are separated by a
newline (‘n’).
CSV File management in C++ is similar to
text-type file management, except for a
few modifications.
4. Each line of the file is a data record.
Each record consists of one or
more fields.
Each line will have the same number of
fields.
CSV is a common data exchange format
that is widely supported by consumer,
business, and scientific applications.
It is a plain text using a character
encoding such as ASCII, various Unicode
character encoding .
A CSV file does not require a specific
5. Features Of CSV File :
The files have a simple structure and are human-readable.
The data can be easily imported or exported into other
programs.
CSV file format can be easily and accurately compressed.
The running costs are not high.
Perfect fit for getting data out of one application and into
another one.
CSV files are smaller in size than the alternatives and faster to
handle.
The format is widely adopted by other people within an
organization.
6. Uses Of A CSV File :
To View a Data Table.
To Save a Data Table to Disk.
To Retrieve a Data Table in to a Spreadsheet Application or
Import the Data Table into a Database Application.
To Retrieve a Data Table into an ASCII Text Editor or Word-
Processing Application.
CSV files can be used in place of Excel files as they
are lightweight and compact, which means they take up less
space and can be transferred faster than Excel files .
7. File Functions In C++ :
open() – This is used to create a file.
read() – This is used to read the data from the
file.
write() – This is used to write new data to file.
close() – This is used to close the file.
get() – This is used to access the character array.
getline() – This allows accepting and reading
single and multiple line strings from the input
stream.
8. put() – This is used to write a line or string to
the output stream.
seekg() – This allows you to seek an arbitrary
position in a file.
tellg() – This tells the current pointer position
in the text file.
seekp() – This moves the pointer to the
desired location.
tellp() – This tells the current put position of
the pointer in the stream.
9. Modes Of Opening A File In C++ :
in - It opens the file for reading .
out - It opens the file for writing .
binary - It is used to perform operations in binary mode rather
than text .
ate - The output position starts at the end of the file .
app - All output operations happen at the end of the file,
appending to its existing contents .
trunc - Any contents that existed in the file before it is open
are discarded .
10. CSV File Operations :
Create
operation:
The create operation is similar to creating a text
file .
It is used to open an existing csv file or create a
new file .
After creating the file we can input data from
the user and write it to the CSV file using the file
pointer and appropriate delimiters(‘, ‘) between
different columns and ‘n’ after the end of each
row.
Syntax :
11. Writing In a CSV File
:
To write to a CSV file, we first need to
create a file object and open the file in
write mode using the ofstream object.
Then, we can write data to the file using
the insertion operator(<<).
We should separate the values with a
comma to ensure that the values are
stored in separate columns.
Finally, We should close the file using
the close() method.
12. Reading From a CSV File :
To read from a CSV file, we first need
to create a file object and open the file
in read mode using the ifstream object
.
Then, we can use the getline() method
to read the contents of the file line by
line.
Whatever data read from the file, is
stored in string format.
Finally, we should close the file using
the close() method.
13. Deleting a Record :
To delete from a CSV file, open the existing
file in input mode .
Create a new file to store the non-deleted
data.
Read data from a file and compare it with the
user input.
Write all the updated records, except the data
to be deleted, onto a new file.
Remove the old file, and rename the new file,
with the old file’s name.
Finally, We should close the file using the
close() method.
14. Errors And Exceptions When Reading Or
Writing To A CSV File :
File Not Found : If the file being read cannot be
found, an error or exception can be thrown.
Invalid Format : If the CSV file is in an invalid format,
an error or exception may occur when trying to
parse it.
Data Validation : If data validation fails, an error or
exception can be thrown.
File Permission Denied : If the file being written to
does not have the correct permissions, an error or
exception may occur.
Disk Space : If there is not enough disk space to
write the data, an error or exception may occur.