cs_lang:c
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
cs_lang:c [2011/07/12 10:30] – cedric | cs_lang:c [2011/07/12 10:37] – [Hello World] cedric | ||
---|---|---|---|
Line 6: | Line 6: | ||
====== Simple examples ====== | ====== Simple examples ====== | ||
+ | ===== Hello World ===== | ||
<code c> | <code c> | ||
/* Hello World program */ | /* Hello World program */ | ||
Line 27: | Line 28: | ||
$ ./ | $ ./ | ||
- | Hello Worldcedric | + | Hello World |
- | < | + | </code> |
+ | |||
+ | |||
+ | |||
+ | ===== Read a file ===== | ||
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main () | ||
+ | { | ||
+ | // Open the file | ||
+ | ofstream inputFile (" | ||
+ | // Test | ||
+ | if (!inputFile) | ||
+ | { | ||
+ | cerr << " | ||
+ | exit (1); | ||
+ | } | ||
+ | char buf [1024]; | ||
+ | // Until there are no more lines in the file, | ||
+ | // read and display it. | ||
+ | while (!inputFile.eof()) | ||
+ | { | ||
+ | inputFile.getline (buf, | ||
+ | cout << buf << endl;; | ||
+ | } | ||
+ | // Close the file | ||
+ | inputFile.close ();; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Equivalent in python ===== | ||
+ | <code python> | ||
+ | for line in open(" | ||
+ | print line | ||
+ | </code> |
cs_lang/c.txt · Last modified: 2012/09/30 23:32 by cedric