我已经告诉别人,编写using namespace std;代码是错误的,我应该用std::cout和std::cin直接代替.
为什么被using namespace std;认为是不好的做法?是低效还是冒着声明模糊变量(与名称std空间中的函数具有相同名称的变量)的风险?它会影响性能吗?
由于ANSI C99存在_Bool或bool通过stdbool.h.但是printfbool 还有一个格式说明符吗?
我的意思是伪代码:
bool x = true;
printf("%B\n", x);
Run Code Online (Sandbox Code Playgroud)
哪个会打印:
true
Run Code Online (Sandbox Code Playgroud) I'm a beginner in C++. Why does this code gives me back '1' when I write it out?
cout << (false||(!false));
It writes out '1', which is equivalent with 'true'. Why does it give back true instead of false? How does it decide whether the statement is true or not?
我只是在摆弄这个函数,不知何故回文返回 74。我正在使用 Visual studio 2022。它是否应该不返回任何内容并捕获编译器错误,因为在下面的情况下永远不会返回 false?
bool palindromes(string str) {
if (str.length() == 0 || str.length() == 1) return true;
if (str[0] == str[str.length() - 1])
palindromes(str.substr(1, str.length() - 2));
else
return false;
}
int main()
{
cout << palindromes("lol");
}
Run Code Online (Sandbox Code Playgroud)