Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831
{"id":14466,"date":"2015-05-06T21:52:44","date_gmt":"2015-05-07T02:52:44","guid":{"rendered":"https:\/\/mitzihernandez.withknown.com\/2015\/mastery28-tc1017"},"modified":"2015-05-06T21:52:44","modified_gmt":"2015-05-07T02:52:44","slug":"mastery28-tc1017-3","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101winter2015\/2015\/mastery28-tc1017-3\/","title":{"rendered":"#mastery28 #TC1017"},"content":{"rendered":"
\n

\u00a0<\/p>\n

#mastery<\/a>28 #TC<\/a>1017<\/span><\/span><\/p>\n

Reading and writing of files in C++<\/span><\/p>\n

So far, we have been using the\u00a0iostream\u00a0standard library, which provides\u00a0cin\u00a0and\u00a0coutmethods for reading from standard input and writing to standard output respectively.<\/span><\/p>\n

This tutorial will teach you how to read and write from a file. This requires another standard C++ library called\u00a0fstream, which defines three new data types:<\/span><\/p>\n\n\n\n\n\n\n
\n

Data Type<\/span><\/p>\n<\/td>\n

\n

Description<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ofstream<\/span><\/p>\n<\/td>\n

\n

This data type represents the output file stream and is used to create files and to write information to files.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ifstream<\/span><\/p>\n<\/td>\n

\n

This data type represents the input file stream and is used to read information from files.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

fstream<\/span><\/p>\n<\/td>\n

\n

This data type represents the file stream generally, and has the capabilities of both ofstream and ifstream which means it can create files, write information to files, and read information from files.<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

To perform file processing in C++, header files and must be included in your C++ source file.<\/fstream><\/iostream><\/span><\/p>\n

Opening a File:<\/span><\/p>\n

A file must be opened before you can read from it or write to it. Either the\u00a0ofstream\u00a0orfstream\u00a0object may be used to open a file for writing and ifstream object is used to open a file for reading purpose only.<\/span><\/p>\n

Following is the standard syntax for open() function, which is a member of fstream, ifstream, and ofstream objects.<\/span><\/p>\n

\n

#D6D6D6 1.0pt; mso-border-alt: solid #D<\/a>6D6D6 .75pt; padding: 4.0pt 4.0pt 4.0pt 4.0pt; background: #EEEEEE;”><\/p>\n

void<\/span> open<\/span>(<\/span>const<\/span> char<\/span> *<\/span>filename<\/span>,<\/span> ios<\/span>::<\/span>openmode mode<\/span>);<\/span><\/p>\n<\/div>\n

Here, the first argument specifies the name and location of the file to be opened and the second argument of the\u00a0open()\u00a0member function defines the mode in which the file should be opened.<\/span><\/p>\n\n\n\n\n\n\n\n\n
\n

Mode Flag<\/span><\/p>\n<\/td>\n

\n

Description<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ios::app<\/span><\/p>\n<\/td>\n

\n

Append mode. All output to that file to be appended to the end.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ios::ate<\/span><\/p>\n<\/td>\n

\n

Open a file for output and move the read\/write control to the end of the file.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ios::in<\/span><\/p>\n<\/td>\n

\n

Open a file for reading.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ios::out<\/span><\/p>\n<\/td>\n

\n

Open a file for writing.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ios::trunc<\/span><\/p>\n<\/td>\n

\n

If the file already exists, its contents will be truncated before opening the file.<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

You can combine two or more of these values by\u00a0ORing them together. For example if you want to open a file in write mode and want to truncate it in case it already exists, following will be the syntax:<\/span><\/p>\n

\n

#D6D6D6 1.0pt; mso-border-alt: solid #D<\/a>6D6D6 .75pt; padding: 4.0pt 4.0pt 4.0pt 4.0pt; background: #EEEEEE;”><\/p>\n

ofstream outfile<\/span>;<\/span><\/p>\n

outfile<\/span>.<\/span>open<\/span>(<\/span>“file.dat”<\/span>,<\/span> ios<\/span>::<\/span>out<\/span> |<\/span> ios<\/span>::<\/span>trunc <\/span>);<\/span><\/p>\n<\/div>\n

Similar way, you can open a file for reading and writing purpose as follows:<\/span><\/p>\n

\n

#D6D6D6 1.0pt; mso-border-alt: solid #D<\/a>6D6D6 .75pt; padding: 4.0pt 4.0pt 4.0pt 4.0pt; background: #EEEEEE;”><\/p>\n

fstream\u00a0 afile<\/span>;<\/span><\/p>\n

afile<\/span>.<\/span>open<\/span>(<\/span>“file.dat”<\/span>,<\/span> ios<\/span>::<\/span>out<\/span> |<\/span> ios<\/span>::<\/span>in<\/span> );<\/span><\/p>\n<\/div>\n

Closing a File<\/span><\/p>\n

When a C++ program terminates it automatically closes flushes all the streams, release all the allocated memory and close all the opened files. But it is always a good practice that a programmer should close all the opened files before program termination.<\/span><\/p>\n

Following is the standard syntax for close() function, which is a member of fstream, ifstream, and ofstream objects.<\/span><\/p>\n

\n

#D6D6D6 1.0pt; mso-border-alt: solid #D<\/a>6D6D6 .75pt; padding: 4.0pt 4.0pt 4.0pt 4.0pt; background: #EEEEEE;”><\/p>\n

void<\/span> close<\/span>();<\/span><\/p>\n<\/div>\n

Writing to a File:<\/span><\/p>\n

While doing C++ programming, you write information to a file from your program using the stream insertion operator (<\/span><\/p>\n

Reading from a File:<\/span><\/p>\n

You read information from a file into your program using the stream extraction operator (>>) just as you use that operator to input information from the keyboard. The only difference is that you use an\u00a0ifstream\u00a0or\u00a0fstream\u00a0object instead of the\u00a0cin\u00a0object.<\/span><\/p>\n

\u00a0<\/p>\n

\u00a0<\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

\n

 <\/p>\n

#mastery<\/a>28 #TC<\/a>1017<\/span><\/span><\/p>\n

Reading and writing of files in C++<\/span><\/p>\n

So far, we have been using the iostream standard library, which provides cin and coutmethods for reading from standard input and writing to standard output respectively.<\/span><\/p>\n

This tutorial will teach you how to read and write from a file. This requires another standard C++ library called fstream, which defines three new data types:<\/span><\/p>\n\n\n\n\n\n\n
\n

Data Type<\/span><\/p>\n<\/td>\n

\n

Description<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ofstream<\/span><\/p>\n<\/td>\n

\n

This data type represents the output file stream and is used to create files and to write information to files.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ifstream<\/span><\/p>\n<\/td>\n

\n

This data type represents the input file stream and is used to read information from files.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

fstream<\/span><\/p>\n<\/td>\n

\n

This data type represents the file stream generally, and has the capabilities of both ofstream and ifstream which means it can create files, write information to files, and read information from files.<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

To perform file processing in C++, header files and must be included in your C++ source file.<\/span><\/p>\n

Opening a File:<\/span><\/p>\n

A file must be opened before you can read from it or write to it. Either the ofstream orfstream object may be used to open a file for writing and ifstream object is used to open a file for reading purpose only.<\/span><\/p>\n

Following is the standard syntax for open() function, which is a member of fstream, ifstream, and ofstream objects.<\/span><\/p>\n

\n

#D6D6D6 1.0pt; mso-border-alt: solid #D<\/a>6D6D6 .75pt; padding: 4.0pt 4.0pt 4.0pt 4.0pt; background: #EEEEEE;”><\/p>\n

void<\/span> open<\/span>(<\/span>const<\/span> char<\/span> *<\/span>filename<\/span>,<\/span> ios<\/span>::<\/span>openmode mode<\/span>);<\/span><\/p>\n<\/div>\n

Here, the first argument specifies the name and location of the file to be opened and the second argument of the open() member function defines the mode in which the file should be opened.<\/span><\/p>\n\n\n\n\n\n\n\n\n
\n

Mode Flag<\/span><\/p>\n<\/td>\n

\n

Description<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ios::app<\/span><\/p>\n<\/td>\n

\n

Append mode. All output to that file to be appended to the end.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ios::ate<\/span><\/p>\n<\/td>\n

\n

Open a file for output and move the read\/write control to the end of the file.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ios::in<\/span><\/p>\n<\/td>\n

\n

Open a file for reading.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ios::out<\/span><\/p>\n<\/td>\n

\n

Open a file for writing.<\/span><\/p>\n<\/td>\n<\/tr>\n

\n

ios::trunc<\/span><\/p>\n<\/td>\n

\n

If the file already exists, its contents will be truncated before opening the file.<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

You can combine two or more of these values by ORing them together. For example if you want to open a file in write mode and want to truncate it in case it already exists, following will be the syntax:<\/span><\/p>\n

\n

#D6D6D6 1.0pt; mso-border-alt: solid #D<\/a>6D6D6 .75pt; padding: 4.0pt 4.0pt 4.0pt 4.0pt; background: #EEEEEE;”><\/p>\n

ofstream outfile<\/span>;<\/span><\/p>\n

outfile<\/span>.<\/span>open<\/span>(<\/span>“file.dat”<\/span>,<\/span> ios<\/span>::<\/span>out<\/span> |<\/span> ios<\/span>::<\/span>trunc <\/span>);<\/span><\/p>\n<\/div>\n

Similar way, you can open a file for reading and writing purpose as follows:<\/span><\/p>\n

\n

#D6D6D6 1.0pt; mso-border-alt: solid #D<\/a>6D6D6 .75pt; padding: 4.0pt 4.0pt 4.0pt 4.0pt; background: #EEEEEE;”><\/p>\n

fstream  afile<\/span>;<\/span><\/p>\n

afile<\/span>.<\/span>open<\/span>(<\/span>“file.dat”<\/span>,<\/span> ios<\/span>::<\/span>out<\/span> |<\/span> ios<\/span>::<\/span>in<\/span> );<\/span><\/p>\n<\/div>\n

Closing a File<\/span><\/p>\n

When a C++ program terminates it automatically closes flushes all the streams, release all the allocated memory and close all the opened files. But it is always a good practice that a programmer should close all the opened files before program termination.<\/span><\/p>\n

Following is the standard syntax for close() function, which is a member of fstream, ifstream, and ofstream objects.<\/span><\/p>\n

\n

#D6D6D6 1.0pt; mso-border-alt: solid #D<\/a>6D6D6 .75pt; padding: 4.0pt 4.0pt 4.0pt 4.0pt; background: #EEEEEE;”><\/p>\n

void<\/span> close<\/span>();<\/span><\/p>\n<\/div>\n

Writing to a File:<\/span><\/p>\n

While doing C++ programming, you write information to a file from your program using the stream insertion operator (<\/span><\/p>\n

Reading from a File:<\/span><\/p>\n

You read information from a file into your program using the stream extraction operator (>>) just as you use that operator to input information from the keyboard. The only difference is that you use an ifstream or fstream object instead of the cin object.<\/span><\/p>\n

 <\/p>\n

 <\/span><\/p>\n<\/div>\n

Continue reading →<\/span><\/a><\/p>\n","protected":false},"author":165,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3,26],"tags":[395,519,517,518,144,396,555,234,497,213,127,486,40,287],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/14466"}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/users\/165"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/comments?post=14466"}],"version-history":[{"count":6,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/14466\/revisions"}],"predecessor-version":[{"id":19507,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/14466\/revisions\/19507"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/media?parent=14466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/categories?post=14466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/tags?post=14466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}