C++程序是在VC++2010中编译的,而不是在Visual C++6.0中编译的

C++ program gets compiled in VC++ 2010 but not in Visual C++ 6.0

本文关键字:编译 Visual C++6 C++ 程序 VC++2010      更新时间:2023-10-16

我不会粘贴整个程序,只粘贴包含的文件和错误,我非常确信,错误就在那里!

VS 2010 中包含的文件

#include <cstdlib>
#include <windows.h>
#include "iostream"
#include "conio.h"
#include "vector"
#include "math.h"
#include <string.h>
#include <bitset>

Visual C++6.0 中包含的文件

#include <cstdlib>
#include <windows.h>
#include "iostream"
#include "conio.h"
#include "vector"
#include "math.h"
#include <string.h>
#include <bitset>
#include <String>

好吧,只有一个区别,我在Visual C++2006中添加了#include <String>,这个特定的文件减少了读取为的错误

错误C2678:二进制"!=":没有定义接受类型为()"class std::basic_string,class std:::allocater>"的左侧操作数的运算符(或者没有可接受的转换)

我在VS2006中仍然面临的其他主要错误是

线路:str.append(to_string((long double)(value)));

错误:error C2065: 'to_string' : undeclared identifier

线路:vector <vector <float>> distOfSectionPoint, momentAtSectionPoint, preFinalMoment, finalMoments, momentAtSectionPtOnPtLoadProfile ;

错误:error C2208: 'class std::vector' : no members defined using this type

有人能解释一下Visual C++2006中出了什么问题吗??

假设to_stringstd::to_string,那么这是一个C++11函数,在旧的编译器中不可用。你可以拼凑出大致相同的东西,比如

template <typename T>
std::string nonstd::to_string(T const & t) {
    std::ostringstream s;
    s << t;
    // For bonus points, add some error checking here
    return s.str();
}

涉及vector的错误是由两个闭合尖括号引起的,较旧的编译器会将其解释为单个>>标记。在它们之间添加一个空格:

vector<vector<float> >
                    ^

目前还不太清楚您使用的是哪种编译器,因为当时还没有Visual C++2006。如果你说的是Visual C++6.0(1998年),那么你可能就完蛋了。从那时起,已经进行了两次主要的语言修订,这使得编写该编译器和现代编译器都支持的代码变得非常困难。如果你指的是2005年或2008年,那么就要小心避免使用C++11特性。

错误C2065:"to_string":未声明的标识符

std::to_string()是VS2010支持的C++11功能。任何早期版本的Microsoft编译器都不支持它。boost::lexical_cast是一种替代方案。


错误C2208:"class std::vector":没有使用此类型定义成员

C++11和VS2010允许使用CCD_ 12,而C++11之前的版本则不允许。需要更改为:

vector <vector <float> > distOfSectionPoint,
                    //^ space here