我已经告诉别人,编写using namespace std;代码是错误的,我应该用std::cout和std::cin直接代替.
为什么被using namespace std;认为是不好的做法?是低效还是冒着声明模糊变量(与名称std空间中的函数具有相同名称的变量)的风险?它会影响性能吗?
在C++中通常用某种前缀命名成员变量来表示它们是成员变量而不是局部变量或参数.如果你来自MFC背景,你可能会使用m_foo.我myFoo偶尔也见过.
C#(或者可能只是.NET)似乎建议只使用下划线,如_foo.这是否允许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) 我在我的代码中发布了一个问题,其唯一的#include指令如下:
#include <bits/stdc++.h>
Run Code Online (Sandbox Code Playgroud)
我的老师告诉我这样做,但在评论部分,我被告知我不应该这样做.
为什么?
c++ portability c++-faq turbo-c++ implementation-defined-behavior
c++ ×4
c++-faq ×3
clang ×1
implementation-defined-behavior ×1
namespaces ×1
portability ×1
standards ×1
std ×1
turbo-c++ ×1
visual-c++ ×1