从 Dev-C++ 出发到 VC++

发布于 2024-09-16 09:10:27 字数 433 浏览 7 评论 0原文

是的,这是一个菜鸟问题...

到目前为止,我一直在我的所有项目中使用 Dev-C++,但它已经过时了,所以库在哪里。所以我打开了 Visual C++ 副本并复制了代码。当我编译时,会弹出一百万个错误,就好像我的代码中的每一行都是狗屎一样。我不想从头开始这个项目。

问题:为什么Dev-C++和VC++编译不同???我听说他们使用不同的编译器,但它仍然是 C++。我看到的第一个错误是 const char* 和 std::string 之间的比较无效。

不管怎样,有什么办法可以让VC++对编程的要求不那么严格,就像Dev-C++一样。或者我应该了解 Dec-C++ 和 VC++ 编译器之间的一些主要区别。

大多数错误似乎与 std::string 相关,或 LPCWSTR (我可以自己修复)。

很抱歉这个非常广泛且无用的话题,我知道。

-亚历克斯

Yes, it's a noob question...

I have been using Dev-C++ for all my projects so far, but it is incredibly outdated, and so where the libraries. So I opened up my copy of Visual C++ and copied the code. When I compile, a million errors pop up, as if every second line of my code is shit. I would hate to start the project again from scratch.

Question: Why is it that Dev-C++ and VC++ compile differently??? I've heard they use different compilers, but its still C++. The first error I looked at was an invalid comparison between a const char* and a std::string.

Anyway, is there any way to make VC++ less strict on programming, as is Dev-C++. Or are there a few major differences between Dec-C++ and VC++ compilers that I should know about.

Most of the errors seem to be std::string related, or LPCWSTR (i can fix that myself).

Sorry about this very broad and useless topic, I'm knew.

-Alex

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

简单 2024-09-23 09:10:27

首先,需要注意几点,因为许多 Dev-C++ 用户都感到困惑(我曾经是这样)

Dev-C++ 不是编译器。编译器是 GCC(或者更准确地说,是 GCC 的修改版本,以便它可以在 Windows 上运行:MinGW)。 Dev-C++ 是一个 IDE:一个带有附加按钮的文本编辑器,单击该按钮时可以使用适当的参数调用 MinGW。

而已。

Visual Studio 也是如此:Visual Studio 是 IDE,它调用 Visual Compiler (vc.exe),它实现 VC++,VC++ 是 Microsoft 对 C++ 标准的实现。

第二:这不是一个菜鸟问题。您已经发现了可移植性问题,这是 C 和 C++ 中令人沮丧的一个重要领域。 StackOverflow 上的很多问题都是由于可移植性问题造成的(代码可以在 Windows 上运行,但不能在 Linux 上运行,等等)。

一般经验法则是 1) 将编译器的警告级别设置为最大,2) 在您的目标平台上并行开发。

希望这有帮助。

First, a few notes, because many Dev-C++ users are confused (I used to be)

Dev-C++ is not a compiler. The compiler is GCC (or, more precisely, a modified version of GCC so that it runs on Windows : MinGW). Dev-C++ is an IDE : a text editor with an additional button which calls MinGW with the appropriate parameters when clicked.

Nothing more.

Same thing for Visual Studio : Visual Studio is the IDE, which calls the Visual Compiler (vc.exe), which implements VC++, which is Microsoft's implementation of the C++ standard.

Second : It's not a noob question. You have discovered portability issues, which is a great area of frustration in C and in C++. A lot of questions on StackOverflow are due to portability problems (a code that works on Windows but not on Linux, etc).

The general rule of thumb is to 1) set your compiler's warning level to the maximum and 2) develop in parallel on all the platforms you're targetting.

Hope this helps.

ゃ懵逼小萝莉 2024-09-23 09:10:27

这并不能回答所有问题,但可能会有所帮助。

默认情况下,VC++ 使用 unicode,而 MinGW(我相信 DevCpp 是基于它的)使用 ansi

这可能可以解释您关于字符串的问题:您基本上是在传递 char* 字符串,其中大多数函数都需要诸如 wchar* 之类的内容。

我建议您修复代码,使其与 unicode 兼容,或者在 VC++ 项目中取消定义 UNICODE 宏(如果不需要 unicode)。

正如您所说,您的旧代码是 C++,代码也是 C++,所以不应该有那么多工作......只要您不依赖于编译器特定的行为。

您能给我们一些出现严重错误的示例吗?我们也许能够提供更准确的帮助。

This will not answer everything, but it might help.

By default, VC++ uses unicode while MinGW (on which DevCpp is based I believe) uses ansi.

This might explain your issues regarding strings: you're basically passing char* strings where most of the functions require something like wchar*.

I suggest that either you fix your code so it becomes unicode compliant, or that you undefine the UNICODE macro in your VC++ project, if unicode is not required.

As you stated, your old code was C++ and the code is C++ as well, so there shouldn't be that much work... as long as you don't rely on compiler specific behaviors.

Could you give us some samples of things that go terribly wrong ? We might be able to help more accurately.

提笔书几行 2024-09-23 09:10:27

项目设置是否相同?也许您需要链接其他 .libs 或添加与 Dev-C++ 中类似的预处理器指令。如果您只是将代码复制并粘贴到项目中,则实际上是将项目设置全部重新设置为默认值,这对于许多项目来说会破坏构建。

除此之外 - 尝试将您收到的最常见错误之一添加到问题中,并添加代码行,也许我们可以发表评论。

Are the project settings the same? Perhaps you need to link in additional .libs or add similar preprocessor directives as you had in Dev-C++. If you just copy and paste the code to a project, you're effectively re-setting the project settings all to default, which for many projects, would break the build.

Apart from that - try adding one of the most common errors you receive to the question, with the line of code, and maybe we can comment.

多彩岁月 2024-09-23 09:10:27

dev-cpp 使用 mingw 作为其编译器。也许通过另一个 IDE 使用更新版本的 mingw 会更幸运。这将有助于外部依赖关系(mingw 使用 gcc,它使用 *.a 文件链接,VC++ 使用 *.lib 文件)。

当您提及字符串和 LPCWSTR 时,请参阅 ereOn 的答案。确保正确定义了 UNICODE 和 _UNICODE(在构建标志中为 -DUNICODE 或在 VC++ 项目选项中)。

Dev-cpp uses mingw as its compiler. Perhaps you will have more luck using an updated version of mingw, through another IDE. This will help with external dependencies (mingw uses gcc which uses *.a files to link to, VC++ uses *.lib files).

As you mentrion string and LPCWSTR, see ereOn's answer. Make sure you have UNICODE and _UNICODE properly defined (in build flags as -DUNICODE or in VC++ project options).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文