如何在 Xcode 3.1.2 的 C++ 项目中创建头文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7204434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:48:56  来源:igfitidea点击:

How do I create header files in C++ projects in Xcode 3.1.2?

xcodeheader-files

提问by mattszo

I am trying to create a header file in my xcode 3.1.2. Here's what I do.

我正在尝试在我的 xcode 3.1.2 中创建一个头文件。这就是我所做的。

I start up xcode, I do a new project and save it as Tricycle.

我启动 xcode,我做了一个新项目并将其保存为 Tricycle。

Then they ask me: Choose a template for your new project. The menu pops up and I go to COMMAND LINE UTILITY to select the "C++ tool".

然后他们问我:为您的新项目选择一个模板。菜单弹出,我去 COMMAND LINE UTILITY 选择“C++ 工具”。

Once I do the project on the already existing main.cpp, I save it as a main.hpp (I even tried main.h) in the project folder Tricycle (which by the way has the directory on my desktop, I did not change anything as to where it goes to reach the source code).

一旦我在已经存在的 main.cpp 上做这个项目,我将它保存为一个 main.hpp(我什至尝试过 main.h)在项目文件夹 Tricycle(顺便说一下我桌面上的目录,我没有改变关于它去哪里到达源代码的任何事情)。

Now this is how I know I've achieved something by saving it as .hpp: it's because the icon changes from that with a blue coloured C to a maroon coloured H.

现在这就是我知道我通过将它保存为 .hpp 取得了一些成就:这是因为图标从蓝色 C 变为栗色 H。

I open up a new project, the one I intend to save as a .cpp, called TricycleNew, again --> command line utility --> c++ tool.

我打开了一个新项目,我打算将这个项目另存为 .cpp,名为 TricycleNew,再次 --> 命令行实用程序 --> c++ 工具。

In the beginning I code: #include "main.hpp"

一开始我编码:#include "main.hpp"

and it says that directory doesn't exist.

它说该目录不存在。

Please help me out, I'm new to programming and especially xcode and I want to advance in my learnings but I can't because of this roadblock.

请帮帮我,我是编程的新手,尤其是 xcode,我想在学习上有所进步,但由于这个障碍我不能。

Ant ideas?

蚂蚁的想法?

回答by Mankarse

It seems like you are making too many projects. You only need one project, and then you need to add additional files to that project (File -> New File -> Header File).

看起来你做的项目太多了。您只需要一个项目,然后您需要向该项目添加其他文件(文件 -> 新建文件 -> 头文件)。