Visual Studio 2017中是否提供C ++ 11? [英] Is C++11 available in Visual Studio 2017?

查看:708
本文介绍了Visual Studio 2017中是否提供C ++ 11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用Visual Studio Community2017。通过在项目属性中查看C ++语言标准,它们仅提供C ++ 14和C ++ 17。由于我的代码已完成使用C ++ 11的编译器进行的先前分配,因此无法使用stoi等功能运行我的代码。我的问题是是否可以将C ++ 11添加到C ++语言标准中?

I am currently using Visual Studio Community 2017. From looking at the C++ Language Standards in the project properties, they only provide C++14 and C++17. Since my code was completed for a previous assignment using a compiler for C++11, I am unable to run my code using functions such as stoi. My question is if there is a way to add C++11 to the language standards for C++?

我正在为GUI创建DLL,我的初始化是:

I am creating a DLL for a GUI, my initializations are:

#include <string>
#include "stdafx.h"

using namespace std;

在这里我要创建一个分数类,主要错误出现在ifstream中:

Here I am creating a fraction class, the main errors follow in the ifstream:

istream& operator>>(istream& in, Fraction& f) {

string number;
in >> number;                           //read the number

size_t delimiter = number.find("/");    //find the delimiter in the string "/"

if (delimiter != string::npos) {            //if delimiter is not empty

    int n = stoi(number.substr(0, delimiter));      //set numerator from string to integer before the "/"
    int d = stoi(number.substr(delimiter + 1));     //set denominator from string to integer after the "/"

    if (d == 0) { //if denominator is 0
        throw FractionException("Illegal denominator, cannot divide by zero.");  //illegal argument throw
    }
    else if (n == 0 && d != 0) {    //numerator is 0, then set values as zero fraction
        f.numVal = 0;
        f.denVal = 1;
    }
    else {                      //set the values into the fraction and normalize and reduce fraction to minimum
        f.numVal = n;
        f.denVal = d;

        f.normalizeAndReduce(f.numVal, f.denVal);
    }
}
else {  //else if there is no delimiter it would be a single integer
    f.numVal = stoi(number);
    f.denVal = 1;
}

return in;
}

我遇到以下错误:

C2679: binary '>>': no operator found which takes a right-hand operator of type 'std::string"
C3861: 'stoi' identifier not found

此方法在日食时效果很好,不确定我在做什么错。

This method worked perfectly fine in eclipse, not sure what I am doing wrong.

推荐答案

Visual C ++ 2017编译器符合C ++ 11 / C ++ 14,但有一些特定的例外:

The Visual C++ 2017 compiler is C++11/C++14 compliant with a few specific exceptions:


  • 表达式SFINAE 已实现,但未完成。

  • 由于可变参数宏的某些错误,对C99预处理程序的完全支持有限

  • 两阶段名称查找在VS 2017中(15.3更新),但不完整,仅在使用 / permissive-

  • Expression SFINAE is implemented, but not complete.
  • Full C99 preprocessor support is limited due to some bugs with variadic macros
  • Two phase name lookup is in VS 2017 (15.3 update) but is incomplete and only active when using /permissive-

编译器不提供特定的C ++ 11模式,默认为C ++ 14,但该标准完全包含C ++ 11。 C ++ 17支持正在进行中,要求您使用 / std:c ++ 17 / std :: c ++ latest 开关。

The compiler does not offer a specific C++11 mode and defaults to C++14, but that standard is fully inclusive of C++11. C++17 support is in progress, and requires you use the /std:c++17 or /std::c++latest switch.

std :: stoi 要求您包括适当的标头,特别是< string>> 要么您忘记包含该标头,要么-您没有处理命名空间解析(要么显式表示为 std :: 或通过使用命名空间std;

std::stoi requires you include the appropriate header, specifically <string>> Either you forgot to include that header -or- you didn't deal with the namespace resolution (either explicitly as std:: or via using namespace std;)


请参见 C VS 2017 15.3中的++ 17功能和STL修复,用于了解自VS 2017起最新的C ++ 11 / C ++ 14 / C ++ 17标准符合性(15.3更新)

See C++17 Features And STL Fixes In VS 2017 15.3 for the latest status of C++11/C++14/C++17 standards conformance as of the VS 2017 (15.3 update)

已更新::既然您已经发布了代码,我发现问题什么都没有了与支持哪种标准有关。您的问题是您不知道预编译标头如何工作的秘密。

UPDATED: Now that you have posted your code, I see that the problem has nothing to do with which standard is supported. Your problem is that you don't know the secrets of how Precompiled Headers work.

更改:

#include <string>
#include "stdafx.h"

至:

#include "stdafx.h"
#include <string>

-或-添加 #include< string> 直接转到预编译的头文件 stdafx.h

-or- add #include <string> to the precompiled header stdafx.h directly.

请参见创建预编译的头文件

这篇关于Visual Studio 2017中是否提供C ++ 11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆