简体   繁体   English

C++ 17 在 visual studio 2017 上编程?

[英]C++ 17 programming on visual studio 2017?

In title, I am specific about the task that I want to achieve.在标题中,我具体说明了我想要完成的任务。 I want to utilize the c++17 features such as parallel STL etc. On visual studio 2017, I configure to c++17 under project properties for language.我想利用 c++17 功能,例如并行 STL 等。在 visual studio 2017 上,我在语言的项目属性下配置为 c++17。 Even after doing this I get the error with #include that no execution file.即使在这样做之后,我也会收到 #include 没有执行文件的错误。 I am just starting with simple example of array addition in parallel with C++ 17 algorithms.我只是从与 C++ 17 算法并行的数组加法的简单示例开始。 How do I resolve this?我该如何解决这个问题?

Source:来源:

#include <stddef.h>
#include <stdio.h>
#include <algorithm>
#include <execution>
#include <chrono>
#include <random>
#include <ratio>
#include <vector>

using std::chrono::duration;
using std::chrono::duration_cast;
using std::chrono::high_resolution_clock;
using std::milli;
using std::random_device;
using std::sort;
using std::vector;


const size_t testSize = 1'000'000;
const int iterationCount = 5;

void print_results(const char *const tag, const vector<double>& sorted,
    high_resolution_clock::time_point startTime,
    high_resolution_clock::time_point endTime) {
    printf("%s: Lowest: %g Highest: %g Time: %fms\n", tag, sorted.front(),
        sorted.back(),
        duration_cast<duration<double, milli>>(endTime - startTime).count());
}

int main() {
    random_device rd;

    // generate some random doubles:
    printf("Testing with %zu doubles...\n", testSize);
    vector<double> doubles(testSize);
    for (auto& d : doubles) {
        d = static_cast<double>(rd());
    }

    // time how long it takes to sort them:
    for (int i = 0; i < iterationCount; ++i)
    {
        vector<double> sorted(doubles);
        const auto startTime = high_resolution_clock::now();
        sort(sorted.begin(), sorted.end());
        const auto endTime = high_resolution_clock::now();
        print_results("Serial", sorted, startTime, endTime);
    }
}

and this is error: Error C1083 Cannot open include file: 'execution': No such file or directory这是错误:Error C1083 Cannot open include file: 'execution': No such file or directory

Task that I want to achieve is that C++17 with CUDA GPU. Both new to me although not c++ in itself.我想要完成的任务是 C++17 和 CUDA GPU。虽然不是 c++ 本身,但对我来说都是新的。 But I am interested in parallel STL of C++17 with CUDA. I want to start from base.但我对 C++17 的并行 STL 和 CUDA 感兴趣。我想从基础开始。 Any suggestions will help me?有什么建议可以帮助我吗?

Thanks, Govind谢谢,戈温德

Please check if the header file is included in the header file directory.请检查header文件是否包含在header文件目录下。 the C++ headers path are: C++ 标头路径是:

1.C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include 1.C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include

2.C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt 2.C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt

The first contains standard C++ headers such as iostream.第一个包含标准 C++ 标头,例如 iostream。 The second contains legacy C headers such as stdio.h.第二个包含旧版 C 标头,例如 stdio.h。

If you are going to use C++ to develop desktop applications, I recommend you to refer to my setup.如果你打算使用C++开发桌面应用,我建议你参考我的设置。

在此处输入图像描述

Also I tested your code on VS2022 without any errors.我也在 VS2022 上测试了你的代码,没有任何错误。 So I suggest you to use a higher version of VS and install the environment you need.所以建议大家使用高版本的VS,安装好自己需要的环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM