相关疑难解决方法(0)

为什么"使用命名空间std"被认为是不好的做法?

我已经告诉别人,编写using namespace std;代码是错误的,我应该用std::coutstd::cin直接代替.

为什么被using namespace std;认为是不好的做法?是低效还是冒着声明模糊变量(与名称std空间中的函数具有相同名称的变量)的风险?它会影响性能吗?

c++ namespaces using-directives std c++-faq

2486
推荐指数
36
解决办法
78万
查看次数

bool的printf格式说明符是什么?

由于ANSI C99存在_Boolbool通过stdbool.h.但是printfbool 还有一个格式说明符吗?

我的意思是伪代码:

bool x = true;
printf("%B\n", x);
Run Code Online (Sandbox Code Playgroud)

哪个会打印:

true
Run Code Online (Sandbox Code Playgroud)

c c++ printf boolean

413
推荐指数
5
解决办法
59万
查看次数

(C++) Why does the '||' logical operator gives back 1?

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?

c++

5
推荐指数
3
解决办法
197
查看次数

为什么这个布尔函数返回 true (74) 而程序显示 74?

我只是在摆弄这个函数,不知何故回文返回 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)

c++

0
推荐指数
1
解决办法
93
查看次数

标签 统计

c++ ×4

boolean ×1

c ×1

c++-faq ×1

namespaces ×1

printf ×1

std ×1

using-directives ×1