valarray的范围循环[关闭]

问题描述 投票:1回答:1

如何在现代C ++中对valarray使用range-for循环?

test.cpp

#include <fstream>
#include <valarray>

void test(std::valarray<float> const& v){ 
  printf( "%s", "first" );
  for (float i : v){
    printf( "%f", i );
  }
}
int main() {
  std::valarray<float> v(3,0);
  test(v);
  return 0;
}
>$ g++ test.cpp -o test -Wall -std=c++17
>$ ./test
first⏎
c++ valarray
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.