C++ 17 在 Visual Studio 2017 上编程?
在标题中,我具体说明了我想要实现的任务。我想利用 c++17 功能,例如并行 STL 等。在 Visual Studio 2017 上,我在语言的项目属性下配置为 c++17。即使执行此操作后,我也会收到#include 错误,表明没有执行文件。 我只是从与 C++ 17 算法并行的数组加法的简单示例开始。我该如何解决这个问题?
来源:
#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);
}
}
这是错误: 错误C1083无法打开包含文件:'执行':没有这样的文件或目录
我想要实现的任务是带有CUDA GPU的C ++ 17。虽然它们本身都不是 C++,但对我来说都是新的。但我对 C++17 与 CUDA 的并行 STL 感兴趣。我想从基础开始。有什么建议可以帮助我吗?
谢谢, 戈文德
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. Even after doing this I get the error with #include that no execution file.
I am just starting with simple example of array addition in parallel with C++ 17 algorithms. 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
Task that I want to achieve is that C++17 with CUDA GPU. Both new to me although not c++ in itself. But I am interested in parallel STL of C++17 with CUDA. I want to start from base. Any suggestions will help me?
Thanks,
Govind
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请检查头文件目录中是否包含头文件。 C++ 头文件路径为:
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
第一个包含标准 C++ 头文件,例如 iostream。第二个包含旧的 C 头文件,例如 stdio.h。
如果你打算使用C++开发桌面应用程序,我建议你参考我的设置。
我还在VS2022上测试了你的代码,没有任何错误。所以我建议你使用更高版本的VS并安装你需要的环境。
Please check if the header file is included in the header file directory. the C++ headers path are:
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
The first contains standard C++ headers such as iostream. The second contains legacy C headers such as stdio.h.
If you are going to use C++ to develop desktop applications, I recommend you to refer to my setup.
Also I tested your code on VS2022 without any errors. So I suggest you to use a higher version of VS and install the environment you need.