Including source code within the wiki

De Wiki de Calcul Québec
Aller à : Navigation, rechercher
Cette page est une traduction de la page Inclure du code source dans le wiki et la traduction est complétée à 100 % et à jour.

Autres langues :anglais 100% • ‎français 100%

To include source code within the wiki, we are using the extension SyntaxHighlight_GeSHi. You can easily include a code snippet using the tag <syntaxhighlight> </syntaxhighlight>.

Options of the <syntaxhighlight> tag

For a complete list of options, please refer to this page.

lang option

The lang option defines the language used for syntax highlighting. The default language, if this option is omitted, is C++. The complete list of supported languages is available here.

line option

The line option displays line numbers.

Example

Here is an example of a C++ code snippet created with the <syntaxhighlight lang="cpp" line> ... </syntaxhighlight> tag.

  1. #include <iostream>
  2. #include <fstream>
  3. #include <unistd.h>
  4. #include <sstream>
  5. using namespace std;
  6.  
  7. void flushIfBig(ofstream & out, ostringstream & oss, int size, bool force=false) {
  8. 	if (oss.tellp() >= size) {
  9. 		out << oss.str();
  10. 		oss.str(""); //reset buffer
  11. 	}
  12. }
  13. int main() {
  14. 	int buff_size = 50*1024*1024;
  15.  
  16. 	ofstream out ("file.dat");
  17. 	ostringstream oss (ostringstream::app);
  18. 	oss.precision(5);
  19. 	for (int i=0; i<100*buff_size; i++)
  20. 	{
  21. 		oss << i << endl;
  22. 		flushIfBig(out,oss,buff_size);
  23. 	}
  24. 	flushIfBig(out,oss,buff_size,true);
  25. 	out.close();
  26. }
Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Ressources de Calcul Québec
Outils
Partager