html显示高亮c++
生活随笔
收集整理的這篇文章主要介紹了
html显示高亮c++
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
配色與Devc++ 的classic plus 相同
輸入文件名即可,輸出在out.htm中
#include<bits/stdc++.h> #include<windows.h> #define chek(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) #define col(co) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),co) #define br BACKGROUND_RED #define bg BACKGROUND_GREEN #define bb BACKGROUND_BLUE #define bi BACKGROUND_INTENSITY #define fr FOREGROUND_RED #define fg FOREGROUND_GREEN #define fb FOREGROUND_BLUE #define fi FOREGROUND_INTENSITY using namespace std; char hl[150][40]={"asm","do","if","return","typedef","auto","double","inline","short","typeid","bool","dynamic_cast","int","signed","typename","break","else","long","sizeof","union","case","enum","mutable","static","unsigned","catch","explicit","namespace","static_cast","using","char","export","new","struct","virtual","class","extern","operator","switch","void","const","false","private","template","volatile","const_cast","float","protected","this","wchar_t","continue","for","public","throw","while","default","friend","register","true","delete","goto","reinterpret_cast","try","in"}; int l=64; /* theme:0:Highlight Word1:Normal Word2:Definding Word3:char,string Word4:Numbers5:Symbols6:Notes */ int themePAS[]={bb+fr+fg+fb+fi,bb+fg+fr+fi,bb+fg+fi,bb+fg+fb+fi,bb+fg+fb+fi,bb+fr+fi,bb+fi}; void init() {freopen("cppword.hl","r",stdin);char c[40];while (cin>>c){l++;for (int i=0;i<40;i++)hl[l][i]=c[i];}freopen("CON","r",stdin);return; } int check(char p[],int pl) {int tt=0; /* for (int i=0;i<pl;i++){if (!isdigit(p[i])){tt=1;break;}}if (!tt) return 2;*/for (int i=1;i<=l;i++){bool tmp=0;int q=strlen(hl[i]);if (q!=pl) continue;for (int j=0;j<pl;j++)if (hl[i][j]!=p[j]){tmp=1;break;}if (!tmp) return 1;}return 0; } int main() {system("color 1F");char k[100];cout << "請輸入文件名:";cin>>k; // init();freopen(k,"r",stdin);freopen("out.htm","w",stdout);cout << "<div style=\"background-color:white;font-family:courier\">";char c;char g[100],gl=0;while (scanf("%c",&c)!=EOF){//system("pause");if (((c>='A'&&c<='Z')||(c>='a'&&c<='z')||c=='_')||(c<='9'&&c>='0'&&gl!=0)){g[gl]=c;gl++;}else{if (c<='9'&&c>='0'&&gl==0) //Numbers {cout << "<font color=\"purple\">";col(themePAS[4]); cout << c; cout << "</font>" ;continue;}if (gl!=0){ //Highlightif (check(g,gl)==1){cout << "<strong><font color=\"black\">";// col(themePAS[0]);for(int i=0;i<gl;i++){cout<<g[i];}cout << "</font></strong>" ;}else //Normal words {cout << "<font color=\"black\">";col(themePAS[1]);for(int i=0;i<gl;i++){cout<<g[i];}cout << "</font>" ;}}if (c=='#') //Defining {cout << "<font color=\"green\">";col(themePAS[2]);cout << c;while (1){scanf("%c",&c);if (c=='\n') break;else if (c=='<') cout << "<";else if (c==' ') cout << " ";else if (c=='\t') cout << " ";else cout<<c;}cout << "</font> <br>";}else if (c=='\'') //char {cout << "<font color=\"black\">";col(themePAS[3]);cout << c;while(1){scanf("%c",&c);if (c=='\''){cout<<c;break;}else if (c=='<') cout << "<";elseif (c=='\\'){cout << c;scanf("%c",&c);cout << c;}else cout<<c;}cout << "</font>" ;}else if (c=='\"') //String {cout << "<strong><font color=\"blue\">";col(themePAS[3]);cout << c;while(1){scanf("%c",&c);if (c=='\"'){cout<<c;break;}else if (c=='<') cout << "<";elseif (c=='\\'){cout << c;scanf("%c",&c);cout << c;}else cout<<c;}cout << "</font></strong>" ;}else if (c=='\n'){cout << "<br>\n" ;}else if (c=='\t'){cout << "<font color=\"red\"> </font>" ;}else if (c=='<'){cout << "<strong><font color=\"red\"><</font></strong>" ;}else if (c=='/') { //Notesscanf("%c",&c);if (c=='/'){cout << "<i><font color=\"#0099FF\">";cout << "//";while (1){scanf("%c",&c);if (c=='\n') break;else if (c=='<') cout << "<";else if (c==' ') cout << " ";else if (c=='\t') cout << " ";else cout<<c;}cout << "</font></i><br>\n" ;}else if (c=='*'){cout << "<i><font color=\"#0099FF\">";cout << "/*";while (1){scanf("%c",&c);if (c=='*'){cout << c;scanf("%c",&c);if (c=='/'){cout << c;break;}}else if (c=='<') cout << "<";else if (c=='\n') cout << "<br>";else if (c==' ') cout << " ";else if (c=='\t') cout << " ";else cout<<c;}cout << "</font></i><br>\n" ;}}else if (c==' '){cout << "<font color=\"red\"> </font>" ;} //Symbolsif (c!='/'&&c!=' '&&c!='\''&&c!='\"'&&c!='#'&&c!='<'&&c!='\n')cout << "<strong><font color=\"red\">"<<c<<"</font></strong>";gl=0;}}cout << "</div>";fclose(stdout);system("out.htm");return 0; }?
?
?
轉載于:https://www.cnblogs.com/dgklr/p/8473072.html
總結
以上是生活随笔為你收集整理的html显示高亮c++的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JVM内存管理机制和垃圾回收机制
- 下一篇: 100个程序员学习的网站