Note that there are some explanatory texts on larger screens.

plurals
  1. POFile I/O in Every Programming Language
    primarykey
    data
    text
    <p>This has to be a common question that all programmers have from time to time. How do I read a line from a text file? Then the next question is always how do i write it back. </p> <p>Of course most of you use a high level framework in day to day programming (which are fine to use in answers) but sometimes it's nice to know how to do it at a low level too.</p> <p>I myself know how to do it in <code>C</code>, <code>C++</code> and <code>Objective-C</code>, but it sure would be handy to see how it's done in all of the popular languages, if only to help us make a better decision about what language to do our file io in. In particular I think it would be interesting to see how its done in the string manipulation languages, like: <code>python</code>, <code>ruby</code> and of course <code>perl</code>. </p> <p>So I figure here we can create a <strong><em>community resource</em></strong> that we can all <strong><em>star</em></strong> to our profiles and refer to when we need to do <strong>file I/O</strong> in some new language. Not to mention the exposure we will all get to languages that we don't deal with on a day to day basis.</p> <p><strong>This is how you need to answer:</strong></p> <ol> <li>Create a new text file called "<strong>fileio.txt</strong>"</li> <li>Write the first line "hello" to the text file.</li> <li>Append the second line "world" to the text file.</li> <li>Read the second line "world" into an input string.</li> <li>Print the input string to the console.</li> </ol> <p><strong>Clarification:</strong></p> <ul> <li>You should show how to do this in one programming language per answer only.</li> <li>Assume that the text file doesn't exist beforehand</li> <li>You don't need to reopen the text file after writing the first line</li> </ul> <p>No particular limit on the language. <code>C</code>, <code>C++</code>, <code>C#</code>, <code>Java</code>, <code>Objective-C</code> are all great. </p> <p>If you know how to do it in <code>Prolog</code>, <code>Haskell</code>, <code>Fortran</code>, <code>Lisp</code>, or <code>Basic</code> then please go right ahead.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload