相关疑难解决方法(0)

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

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

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

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

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

在C++标识符中使用下划线有哪些规则?

在C++中通常用某种前缀命名成员变量来表示它们是成员变量而不是局部变量或参数.如果你来自MFC背景,你可能会使用m_foo.我myFoo偶尔也见过.

C#(或者可能只是.NET)似乎建议只使用下划线,如_foo.这是否允许C++标准?

c++ standards naming-conventions c++-faq

906
推荐指数
4
解决办法
24万
查看次数

为什么这个程序被三个C++编译器错误地拒绝了?

编写我编写的C++程序时遇到一些困难.

这个程序非常简单,据我所知,它符合C++标准中规定的所有规则.我已经两次阅读整个ISO/IEC 14882:2003以确定.

该计划如下:

在此输入图像描述

这是我尝试使用Visual C++ 2010编译此程序时收到的输出:

c:\dev>cl /nologo helloworld.png
cl : Command line warning D9024 : unrecognized source file type 'helloworld.png', object file assumed
helloworld.png : fatal error LNK1107: invalid or corrupt file: cannot read at 0x5172
Run Code Online (Sandbox Code Playgroud)

沮丧,我尝试了g ++ 4.5.2,但同样无益:

c:\dev>g++ helloworld.png
helloworld.png: file not recognized: File format not recognized
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我认为Clang(版本3.0主干127530)必须工作,因为它的标准一致性受到高度赞扬.不幸的是,它甚至没有给我一个漂亮的,突出显示的错误消息:

c:\dev>clang++ helloworld.png
helloworld.png: file not recognized: File format not recognized
collect2: ld returned 1 exit status
clang++: error: linker (via gcc) command …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors clang visual-c++

469
推荐指数
30
解决办法
32万
查看次数

我为什么不#include <bits/stdc ++.h>?

我在我的代码中发布了一个问题,其唯一的#include指令如下:

#include <bits/stdc++.h>
Run Code Online (Sandbox Code Playgroud)

我的老师告诉我这样做,但在评论部分,我被告知我不应该这样做.

为什么?

c++ portability c++-faq turbo-c++ implementation-defined-behavior

215
推荐指数
6
解决办法
2万
查看次数