[英]C++ program gets compiled in VC++ 2010 but not in Visual C++ 6.0
我不会粘贴整个程序,而只会粘贴包含的文件和错误,正如我非常确定的那样,错误本身就在那里!
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 :: allocator>'类型的左操作数(或没有可接受的转换)
我在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中出了什么问题?
error C2065: 'to_string' : undeclared identifier
std::to_string()
是VS2010支持的C ++ 11功能。 Microsoft编译器的任何早期版本将不支持它。 另一种选择是boost::lexical_cast
。
error C2208: 'class std::vector' : no members defined using this type
C ++ 11和VS2010允许使用>>
但C ++ 11之前的版本不允许。 需要更改为:
vector <vector <float> > distOfSectionPoint,
//^ space here
假设to_string
是std::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功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.