PageRenderTime 60ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/www.cppreference.com/wiki/preprocessor/sharp

https://github.com/tsgates/cclookup
#! | 90 lines | 77 code | 13 blank | 0 comment | 0 complexity | 15b7843ca965ecfff4b998b8a7b6e3ba MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
  4. lang="en" dir="ltr">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <title>preprocessor:sharp</title>
  8. <meta name="generator" content="DokuWiki" />
  9. <meta name="robots" content="index,follow" />
  10. <meta name="date" content="2010-10-28T18:17:02-0700" />
  11. <meta name="keywords" content="preprocessor,sharp" />
  12. <link rel="search" type="application/opensearchdescription+xml" href="http://www.cppreference.com/wiki/lib/exe/opensearch.php" title="C++ Reference" />
  13. <link rel="start" href="../../index.html" />
  14. <link rel="contents" href="http://www.cppreference.com/wiki/preprocessor/sharp?do=index" title="Sitemap" />
  15. <link rel="alternate" type="application/rss+xml" title="Recent Changes" href="http://www.cppreference.com/wiki/feed.php" />
  16. <link rel="alternate" type="application/rss+xml" title="Current Namespace" href="http://www.cppreference.com/wiki/feed.php?mode=list&amp;ns=preprocessor" />
  17. <link rel="alternate" type="text/html" title="Plain HTML" href="http://www.cppreference.com/wiki/_export/xhtml/preprocessor/sharp" />
  18. <link rel="alternate" type="text/plain" title="Wiki Markup" href="http://www.cppreference.com/wiki/_export/raw/preprocessor/sharp" />
  19. <link rel="canonical" href="sharp" />
  20. <link rel="stylesheet" media="screen" type="text/css" href="../lib/exe/css.php@t=custom1&amp;tseed=1289693594" />
  21. <link rel="stylesheet" media="all" type="text/css" href="../lib/exe/css.php@s=all&amp;t=custom1&amp;tseed=1289693594" />
  22. <link rel="stylesheet" media="print" type="text/css" href="../lib/exe/css.php@s=print&amp;t=custom1&amp;tseed=1289693594" />
  23. <script type="text/javascript" ><!--//--><![CDATA[//><!--
  24. var NS='preprocessor';var JSINFO = {"id":"preprocessor:sharp","namespace":"preprocessor"};
  25. //--><!]]></script>
  26. <script type="text/javascript" charset="utf-8" src="../lib/exe/js.php@tseed=1289693594" ></script>
  27. </head>
  28. <body>
  29. <div class="dokuwiki export">
  30. <h2 class="sectionedit1"><a name="and" id="and"># and ##</a></h2>
  31. <div class="level2">
  32. <p>
  33. The # and ## preprocessor operators are used with the <a href="define" class="wikilink1" title="preprocessor:define">#define</a> preprocessor directive.
  34. </p>
  35. <ul>
  36. <li class="level1"><div class="li"> Using # causes the first argument after the # to be returned as a string in quotes. </div>
  37. </li>
  38. <li class="level1"><div class="li"> Using ## concatenates what&#039;s before the ## with what&#039;s before or after it.</div>
  39. </li>
  40. </ul>
  41. <p>
  42. For example, the command
  43. </p>
  44. <pre class="cpp code cpp"> <span class="co2">#define to_string( s ) # s</span></pre>
  45. <p>
  46. will make the compiler turn this command
  47. </p>
  48. <pre class="cpp code cpp"> <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> to_string<span class="br0">&#40;</span> Hello World<span class="sy3">!</span> <span class="br0">&#41;</span> <span class="sy1">&lt;&lt;</span> endl<span class="sy4">;</span></pre>
  49. <p>
  50. into
  51. </p>
  52. <pre class="cpp code cpp"> <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;Hello World!&quot;</span> <span class="sy1">&lt;&lt;</span> endl<span class="sy4">;</span></pre>
  53. <p>
  54. Here is an example of the ## command:
  55. </p>
  56. <pre class="cpp code cpp"> <span class="co2">#define concatenate( a, b ) a ## b</span>
  57. ...
  58. <span class="kw4">int</span> xy <span class="sy1">=</span> <span class="nu0">10</span><span class="sy4">;</span>
  59. ...</pre>
  60. <p>
  61. This code will make the compiler turn
  62. </p>
  63. <pre class="cpp code cpp"> <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> concatenate<span class="br0">&#40;</span> x, y <span class="br0">&#41;</span> <span class="sy1">&lt;&lt;</span> endl<span class="sy4">;</span></pre>
  64. <p>
  65. into
  66. </p>
  67. <pre class="cpp code cpp"> <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> xy <span class="sy1">&lt;&lt;</span> endl<span class="sy4">;</span></pre>
  68. <p>
  69. which will, of course, display &#039;10&#039; to standard output.
  70. </p>
  71. <p>
  72. Related topics: <a href="define" class="wikilink1" title="preprocessor:define">#define</a>
  73. </p>
  74. </div>
  75. </div>
  76. </body>
  77. </html>