{"id":77,"date":"2009-07-21T22:11:26","date_gmt":"2009-07-21T21:11:26","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=77"},"modified":"2009-07-21T22:33:23","modified_gmt":"2009-07-21T21:33:23","slug":"read-write-files","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/21\/read-write-files\/","title":{"rendered":"Read \/ Write files"},"content":{"rendered":"<p>This tutorial will demonstrate how to read in a file and also output the details to another file. The headers<br \/>\nfstream and iostream<br \/>\nbasically include details on File-streaming (fstream) and In-Output-Streaming (iostream).<\/p>\n<p>I have attached the code within a zip file with the required input file as well.<\/p>\n<p>The namespace denotes which area are you in, for example : maths:algebra would mean you are doing maths and with the topic of Algebra, within the c\/c++ example std::ifstream means that the namespace is std and the function\/variable is ifstream.<\/p>\n<p>NOTE: the { } are the begin and end of a code structure, e.g. While begin; do something; end;<\/p>\n<pre lang=\"cpp\">\n#include <stdio.h><br \/>\n#include <fstream><br \/>\n#include <iostream><\/p>\n<p>using namespace std;\/\/ use the namespace (e.g. instead of putting std::ifstream you just need to put fstream.)<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n       char InStr[100];<br \/>\n       ifstream InFile(\"countrys.txt\",ios::in);\/\/ infile<br \/>\n       ofstream OutFile(\"outcountrys.txt\", ios::out);\/\/ outfile<\/p>\n<p>       while (InFile.getline(InStr,100))\/\/ while reading each line within the file<br \/>\n       {<br \/>\n              printf(\"%s\\n\", InStr);\/\/ output the read line to the console<br \/>\n              OutFile << \n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will demonstrate how to read in a file and also output the details to another file. The headers fstream and iostream basically include details on File-streaming (fstream) and In-Output-Streaming (iostream). I have attached the code within a zip file with the required input file as well. The namespace denotes which area are you &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/21\/read-write-files\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Read \/ Write files<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[10,9,8,398,400],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-c_and_cpp","tag-c","tag-gcc","tag-gnu","tag-linux","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":16,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":93,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/77\/revisions\/93"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}