[英]How to prevent /* from creating a comment block?
I'm trying to print out the following:我正在尝试打印以下内容:
cout << *pointer1/*pointer2 << endl;
However, because /*
opens a comment block, everything past /*
is treated as a comment.但是,因为
/*
打开了一个注释块,所以 / /*
之后的所有内容都被视为注释。 The solution I've come up so far is this:到目前为止我提出的解决方案是这样的:
int tempPointer = *pointer;
cout << *pointer1/tempPointer << endl;
This works but isn't very elegant.这有效,但不是很优雅。
Is there a way to prevent /*
from creating a comment block in this instance?有没有办法阻止
/*
在这种情况下创建评论块?
Just add a space or put the pointer dereference in brackets.只需添加一个空格或将指针取消引用放在括号中。 (This also improves readability.)
(这也提高了可读性。)
cout << *pointer1 / *pointer2 << endl;
or或者
cout << *pointer1/(*pointer2) << endl;
Put parentheses around the expression:在表达式周围加上括号:
(*pointer2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.