我在写一段代码,要求我忽略注释行(即以#号开头的行)直到行尾。我正在使用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