1

有一个程序我可以在 2008 年下编译一段时间。注意我可以使用 cl 和 Ultimate++ IDE 编译程序。这是一个相当大的程序,所以我不打算在这里发布它。我无法在 Studio 中编译它。

错误是

1>c:\program files\microsoft visual studio 9.0\vc\include\xstring(1735)
: error C2856: #pragma hdrstop cannot be inside an #if block

这似乎很愚蠢,因为那里没有 hdrstop。

预编译的头文件被关闭。

这就是那里:

            if (_Mysize < _Off)
                _String_base::_Xran();  // _Off off end
            if (_Mysize - _Off < _Count)
                _Count = _Mysize - _Off;
            _Traits_helper::copy_s<_Traits>(_Dest, _Dest_size, _Myptr() + _Off, _Count);
            return (_Count);
            }

        void __CLR_OR_THIS_CALL swap(_Myt& _Right)
            {   // exchange contents with _Right <<<<<<<<----------this is the line 
            if (this == &_Right)
                ;   // same object, do nothing
            else if (_Mybase::_Alval == _Right._Alval)
                {   // same allocator, swap control information

谢谢。

4

4 回答 4

3

胡乱猜测。

项目的预编译头文件是否已关闭?他们是否为项目中的每个源文件都关闭了(导致单个文件设置覆盖整个项目设置)。

于 2010-02-26T15:09:11.050 回答
3

我发现了这一点。它是由预编译的头文件引起的,是的,但没有必要关闭它。

当顶层#include "headertobeprecompiled.h"位于#if #endif块内时会发生这种情况。如果可以将其移出错误消息就会消失。

于 2011-10-15T09:29:47.417 回答
0

因为 Visual C++ 调用 cl (工作正常)并且您显然弄乱了标题,所以我要检查的第一件事是包含路径。把它们贴在这里。

于 2010-02-26T13:53:24.083 回答
0

我遇到了完全相同的问题并且也感到困惑,因为我的代码中也没有任何 hdrstop 编译指示。但是,我从脚本(不是 IDE)编译,当我省略编译器选项 /Yc(创建 PCH)时,错误消失了。

于 2011-09-03T22:32:37.217 回答