我在寫一段代碼,要求我忽略註釋行(即以#號開頭的行)直到行尾。我正在使用linux來編寫C++代碼。例如:在添加兩個數字的情況下。在命令提示符下忽略以'#'開頭的行
[email protected]:~ $ ./add
Enter the two numbers to be added
1 #this is the first number
2 #this is the second number
result: 3
所以註釋行可以在任何地方。它只需要忽略整條線並將下一個值作爲輸入。
#include <iostream>
using namespace std;
int main()
{
int a,b;
cout<< "Enter the two numbers to be added:\n";
while(cin >>a >>b)
{
if (a == '#'|| b == '#')
continue;
cout << "Result: "<<a+b;
}
return 0;
}
你能展示你的嘗試?否則,我們必須對你的代碼做出假設。 – 2013-04-08 22:15:25
即時通訊非常新的這個,我不知道如何在這裏添加代碼..但這裏是它.. – 2013-04-08 22:32:17
點擊 - > [編輯] :) – 2013-04-08 22:34:58