我正在嘗試使用rangesc 20 中的庫,并且我有這個簡單的回圈。
for (const int& num : vec | std::views::drop(2)) {
std::cout << num << ' ';
}
我收到一條錯誤訊息,說error: 'std::views' has not been declared. 我沒有收到關于包含標題的任何錯誤。
這是我的 g
g .exe (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
據我所知,只要你有 c 20,它就應該可以作業。
以下示例無法在我的機器上編譯:
#include <iostream>
#include <ranges>
#include <vector>
int main() {
std::cout << "Hello world!";
std::vector <int> vec = {1, 2, 3, 4, 5};
// print entire vector
for (const int& num : vec) {
std::cout << num << ' ';
}
std::cout << "\n";
// print the vector but skip first few elements
for (const int& num : vec | std::views::drop(2)) {
std::cout << num << ' ';
}
return 0;
}
uj5u.com熱心網友回復:
根據編譯器的版本,不同的標準是默認的。因為11.2它是 C 17 AFAIK。
Cou 只需添加一個標志即可編譯:
g --std=c 20 main.cc
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/386157.html
上一篇:在哪里使用std::span?
