C ++程序在VC ++ 2010中编译,但在Visual C ++ 6.0中编译

问题描述 投票:0回答:2

我不会粘贴整个程序,只是包含文件和错误,因为我非常肯定,错误就在于它!

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:binary'!=':没有运算符定义,它接受类型()'类std :: basic_string,类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中出了什么问题?

c++ visual-studio-2010 visual-c++
2个回答
4
投票

假设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功能。


4
投票
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
© www.soinside.com 2019 - 2024. All rights reserved.