<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C++ Tutorial - File I/O</title><link>/technologies/code_exchange/b/blog/posts/c-tutorial---file-i-o</link><description>IntroductionIn the previous tutorial , we talked about inheritance which is a way to reuse variables and methods that are common to multiple classes. It also allows for a class hierarchy to be set up so that methods can work on the most generic class</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: C++ Tutorial - File I/O</title><link>https://community.element14.com/technologies/code_exchange/b/blog/posts/c-tutorial---file-i-o</link><pubDate>Tue, 07 Apr 2015 15:46:37 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:01ad14c6-226f-4856-99e1-bb858d5e6e7e</guid><dc:creator>Former Member</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Your code that writes a file gives a &amp;quot;segmentation fault&amp;quot; in Raspbian, and also some sort of run time error on Windows 7 in Visual Studio 2013. Would you be able to correct this?&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Edit: the solution for Windows 7 in Visual Studio 2013 is found here: &lt;a class="jive-link-external-small" href="http://stackoverflow.com/questions/16883037/remove-secure-warnings-crt-secure-no-warnings-from-projects-by-default-in-vis" rel="nofollow ugc noopener" target="_blank"&gt;http://stackoverflow.com/questions/16883037/remove-secure-warnings-crt-secure-no-warnings-from-projects-by-default-in-vis&lt;/a&gt; --apparently your fopen method is considered deprecated.&lt;/p&gt;&lt;p&gt;Debugging your tutorial is really quite a bit of work!&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=15730&amp;AppID=74&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: C++ Tutorial - File I/O</title><link>https://community.element14.com/technologies/code_exchange/b/blog/posts/c-tutorial---file-i-o</link><pubDate>Thu, 02 May 2013 18:22:18 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:01ad14c6-226f-4856-99e1-bb858d5e6e7e</guid><dc:creator>oneleggedredcow</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Thanks, excellent comment!&amp;nbsp; fstream is definitely the more &amp;quot;c++&amp;quot; way to go about things, whereas what I described was the more &amp;quot;c&amp;quot; way.&amp;nbsp; Personally, I tend to use fopen/fread/fwrite much more, especially for binary files.&amp;nbsp; The only time I use fstream is for reading/writing text files.&amp;nbsp; (And since I haven&amp;#39;t given proper treatment to strings - which is coming next article, I was hesitant to go that route.)&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=15730&amp;AppID=74&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: C++ Tutorial - File I/O</title><link>https://community.element14.com/technologies/code_exchange/b/blog/posts/c-tutorial---file-i-o</link><pubDate>Wed, 01 May 2013 10:05:14 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:01ad14c6-226f-4856-99e1-bb858d5e6e7e</guid><dc:creator>shabaz</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Hi Shaun,&lt;/p&gt;&lt;p&gt;It&amp;#39;s a very useful post as always, the whole tutorial is a great reference.&lt;/p&gt;&lt;p&gt;Another file handling method (useful on Linux/Windows platforms) is to use the fstream library, although this may not be possible on microcontrollers not running Linux.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;#include &amp;lt;fstream&amp;gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;using std::ofstream;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;using std::ifstream;&lt;/p&gt;&lt;p&gt;using std::endl;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;int&lt;/p&gt;&lt;p&gt;main(void)&lt;/p&gt;&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&amp;nbsp; char line[1024];&lt;/p&gt;&lt;p&gt;&amp;nbsp; ofstream out;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; ifstream in(&amp;quot;infile.txt&amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; out.open(&amp;quot;outfile.txt&amp;quot;);&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; while (in.getline(line, 1024))&lt;/p&gt;&lt;p&gt;&amp;nbsp; {&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out &amp;lt;&amp;lt; line &amp;lt;&amp;lt; endl;&lt;/p&gt;&lt;p&gt;&amp;nbsp; }&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; return 0;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=15730&amp;AppID=74&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>