C++标头混乱
因此,在夏季学期前的休息时间里,我尝试自学一点 C++。我正在阅读一本书,但没有使用提供的编译器。相反,我使用 MinGW。我遇到的问题是两个编译器所需的标头似乎有些不同。例如,文本使用
#include <iostream.h>
...MinGW C++ 编译器需要......
#include <iostream>
所以现在我有一个简单的程序来操作我正在尝试运行的字符串,并且文本中提供的标头是
#include <string6.h>
..... .而且我不知道要包含什么标头才能使其运行。事实上,我真的不知道标题是如何工作的。我对 Java 和 Python 有了粗略的了解,仅此而已。我到底需要安装文本附带的编译器吗?在哪里可以找到 MinGW C++ 编译器用于不同数据的标头列表?这是我试图运行的代码...
int main() {
string s1;
string s2;
s1 = "This is a test";
s2 = "and so is this.";
cout << s1;
cout << s2;
return 0;
}
任何有关标头工作一般方式的帮助和见解将不胜感激。我似乎无法理解 MinGW 文档。
So in the down time before summer semester, I'm trying to learn a little C++ on my own. I'm working through a book, but not using the compiler provided. Instead, I'm using MinGW. The problem I've encountered is that the headers the two compilers need appear to be somewhat different. For example, where the text uses
#include <iostream.h>
...the MinGW C++ compiler needs...
#include <iostream>
... so now I have a simple program manipulating strings I'm trying to run, and the header provided in the text is...
#include <string6.h>
...and I don't know what header to include to make it run. In fact, I don't really know how headers work. I have a cursory knowledge of Java and Python and that's it. Do I need to install the compiler that came with the text after all? Where can I find a list of the headers used by the MinGW C++ compiler for different data? Here is the code I was trying to run...
int main() {
string s1;
string s2;
s1 = "This is a test";
s2 = "and so is this.";
cout << s1;
cout << s2;
return 0;
}
Any help and insight into the general way headers work would be much appreciated. I can't seem to make sense out of the MinGW documentation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
给自己买一本新书 - 请参阅权威 C++ 书籍指南和列表寻求建议。
表示法标头在 C++ 标准发布之前(即 1998 年)使用。该标准删除了.h
后缀。它还添加了许多您的书可能未涵盖的功能 - 特别是模板库。
如果您必须使用您的书籍,请从大多数标题中删除
.h
后缀。不过,如果 C 也使用标头,您可以继续使用.h
后缀(例如
),或者在名称前添加前缀c
,如
。但预计会出现一些问题...Get yourself a newer book - see The Definitive C++ Book Guide and List for suggestions.
The
<iostream.h>
notation headers were used before the C++ standard was published - which was in 1998. The standard dropped the.h
suffix.It also added lots of features that your book probably doesn't cover - notably the template library.
If you must use your book, drop the
.h
suffix from most headers. Where the header is also used by C, though, you would either continue to use the.h
suffix (e.g.<stdio.h>
), or prefix the name withc
, as in<cstdio>
. But expect some problems...您最好阅读 MinGW 文档和示例。不同编译器的字符串操作可能略有不同。
您还可以安装 Visual Studio Express,它是免费的。
You better read the MinGW documentation and samples. String manipulation can be a bit different from one compiler to other.
You can also install visual studio express, it's free.