Thread: why not working?

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    99

    why not working?

    Code:
    #include<vector>
    #include<cmath>
    #include<iostream>
    
    
    
    
    
    
    int main()
    {
        std::vector<int> ints{ 0, 1, 2, 3, 4, 5 };
        auto even = [](int i) { return i % 2 == 0;  };
        auto square = [](int i) { return i * i;  };
    
    
        for (int i : ints | std::views::filter(even) |
            std::views::transform(square)) {
            std::cout << i << ' ';
        }
    }
    It says two errors, but I did the example straight from the book...

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What exactly are the errors?

  3. #3
    Registered User
    Join Date
    Dec 2019
    Posts
    99
    Quote Originally Posted by jimblumberg View Post
    What exactly are the errors?
    Says:
    Code:
    main.cpp:17:30: error: ‘std::views’ has not been declared   17 |     for (int i : ints | std::views::filter(even) |
          |                              ^~~~~
    main.cpp:18:14: error: ‘std::views’ has not been declared
       18 |         std::views::transform(square)) {       |              ^~~~~

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You need to compile as C++20, or if your compiler does not support C++20, then you need to upgrade compiler.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Sep 2020
    Posts
    150
    You also need to include <ranges>, then it works with my VS2019

  6. #6
    Registered User
    Join Date
    Dec 2019
    Posts
    99
    I was using C++ 20....

    Quote Originally Posted by laserlight View Post
    You need to compile as C++20, or if your compiler does not support C++20, then you need to upgrade compiler.

  7. #7
    Registered User
    Join Date
    Dec 2019
    Posts
    99
    Can you show your code? Because I used
    Code:
    #include<ranges>
    and it did not work...

    Quote Originally Posted by thmm View Post
    You also need to include <ranges>, then it works with my VS2019

  8. #8
    Registered User
    Join Date
    Sep 2020
    Posts
    150
    It's the same code you posted + the include.
    You also need to set the C++ Language Standard
    why not working?-untitled-1-png
    Attached Images Attached Images why not working?-untitled-1-png 

  9. #9
    Registered User
    Join Date
    Dec 2019
    Posts
    99
    Wow, many thanks. I was using c++ 14, now no longer am. Thank you.

    Quote Originally Posted by thmm View Post
    It's the same code you posted + the include.
    You also need to set the C++ Language Standard
    why not working?-untitled-1-png

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-28-2017, 01:21 PM
  2. Replies: 4
    Last Post: 02-25-2016, 08:49 AM
  3. exp() not working
    By kazman in forum C Programming
    Replies: 2
    Last Post: 03-10-2011, 03:59 AM
  4. /n not working
    By Ghezzo in forum C Programming
    Replies: 3
    Last Post: 09-11-2009, 09:59 PM
  5. Replies: 9
    Last Post: 03-30-2009, 04:09 AM

Tags for this Thread