如何在HTML页面中显示代码(特别是C ++)? [英] How can I show code (specifically C++) in an HTML page?
本文介绍了如何在HTML页面中显示代码(特别是C ++)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用HTML在网站上显示代码?基本上,我有一个C ++程序,我想在我的网站上分享,我想在页面中显示它。
How can I show code in a website using HTML? Basically, I have a C++ program that I'd like to share on my website and I want to show it in the page.
有没有办法显示C ++代码在HTML中,除了使用HTML文本?
Is there anyway to show a C++ code in HTML other than using HTML text?
推荐答案
您可以使用 SyntaxHighlighter 。它将不显眼地增强页面上的代码示例,并为各种语言提供特定的语法高亮显示。
You can use SyntaxHighlighter. It will unobtrusively enhance code samples on your page with specific syntax highlighting for a wide range of languages.
以下是C ++的示例
<head>
<link href="css/shCore.css" rel="stylesheet" type="text/css" />
<link href="css/shThemeDefault.css" rel="stylesheet" type="text/css" />
</head>
<body>
<pre class='brush: cpp'>
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
</pre>
<script src="js/shCore.js"></script>
<script src="js/shBrushCpp.js"></script>
<script>
SyntaxHighlighter.all()
</script>
</body>
这篇关于如何在HTML页面中显示代码(特别是C ++)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文