Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我想请教一下关于cctype和cstddef的问题 #57

Closed
tsyw opened this issue Jul 2, 2016 · 3 comments
Closed

我想请教一下关于cctype和cstddef的问题 #57

tsyw opened this issue Jul 2, 2016 · 3 comments

Comments

@tsyw
Copy link

tsyw commented Jul 2, 2016

使用这两个头文件里面定义的东西是不是不需要加using std::size_t; using std::toupper; 之类的声明?
我看了您的几个答案中没有写,我实际尝试的时候,无论加不加都不影响。

@tsyw
Copy link
Author

tsyw commented Jul 2, 2016

我的想法是:是不是类名需要声明,而类里面的东西不需要加using

@pezy
Copy link
Owner

pezy commented Jul 3, 2016

是不是类名需要声明,而类里面的东西不需要加using

不是,你碰到情况的另有原因。

使用这两个头文件里面定义的东西是不是不需要加using std::size_t; using std::toupper; 之类的声明?

<cctype><cstddef> 你观察到了没,两者都是以 c 开头的,他们原本都是 C语言的库。C++ 为了兼容 C,也将其封入了 STL。

所以当你加上 std 的时候,用的是 STL(c++) 中的函数;当你不加 std 的时候,用的是原生 C 语言的函数。目前绝大部分 C++ 编译器都可以编译 C 程序,所以让你产生了加不加都可以的错觉。

其实,在 C++ 11 之后,加上 std 是比较严谨,恰当的做法。如果我的部分答案没写,应该是疏忽了。回头有空我补上吧。。。

@tsyw
Copy link
Author

tsyw commented Jul 3, 2016

谢谢,看来是我看书不仔细

@tsyw tsyw closed this as completed Jul 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants