MB4*_*B41 1 c++ string if-statement counting
我正在写一个计算代码行的小程序.以下是一行代码的定义: - 包含程序运行所需代码的任何行. - 空白行不是一行代码. - 评论不是一行代码. - 如果在同一行之后有代码和注释,那么它也很重要.
所以我有这段代码(简单的if语句):
found = lineRead.find("/*");
if(found != string::npos)
{
found = lineRead.find("*/");
if(found != string::npos)
inComment = false;
else
inComment == true;
}
return inComment;
Run Code Online (Sandbox Code Playgroud)
假使,假设
String lineRead = "cout<<\"helloworld!\";/*blockcomment"
Bool inComment (is true if the previous line didn't have end block comment token)
Run Code Online (Sandbox Code Playgroud)
所以我的程序到达第一个if语句,因为它/*在那一行找到,查找*/,转到第二个if语句然后直接跳转到return语句而不改变inComment(应该设置为true因为下一行的文本仍然是在块内注释).
谁知道为什么会这样?
| 归档时间: |
|
| 查看次数: |
1312 次 |
| 最近记录: |