测试一下下面几段代码:
Java支持示例,此程序是显示如何处理跳过换行与回车字符影响的猜字游戏程序chenneal1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| import java.io.*;
class test { public static void main(String[] args) throws java.io.IOException { char ch, answer = 'K'; do { do { ch = (char)System.in.read(); } while(ch == '\r' | ch == '\n'); if(ch == answer) System.out.println("right answer"); else System.out.println("wrong answer"); } while (ch != answer); } }
|
C++支持示例,选自C++ Primer习题答案chenneal1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #include <iostream> #include <string> #include <vector> using namespace std; int main() { vector<string*> spvec; string str; cout << "Enter some strings(Ctrl+Z to end)" << endl; while (cin >> str) { string *pstr = new string; *pstr = str; spvec.push_back(pstr); } vector<string*>::iterator iter = spvec.begin(); while (iter != spvec.end()) { cout << **iter << (**iter).size() << endl; iter++; } iter = spvec.begin(); while (iter != spvec.end()) { delete *iter; iter++; } return 0; }
|
看来Hexo默认代码高亮插件表现还是相当不错的^_^。
题图
2015年7月新番《Charlotte》女主友利奈绪。