Auto changes the value in C ++ 11; please delete it, what does it mean?

I am running my code below, which checks if data_timestampmore than two weeks or not. If he is two weeks old, then print hello, otherwise the world prints.

I am a Java developer, I recently started working with C ++. I learned a few things over the Internet, so I use it here in this program.

#include <ctime>
#include <chrono>
#include <iostream>

int main()
{
    // this has to be uint64_t bcoz of old code
    uint64_t data_timestamp = 1406066507000; 

    const auto now = std::chrono::system_clock::now();
    auto twoWeeks = std::chrono::hours(24 * 14);
    auto lastTwoWeeks = now - twoWeeks;

    auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(lastTwoWeeks.time_since_epoch()).count();

    std::cout << "Time stamp in milliseconds since UNIX epoch start: "<< millis << std::endl;

    if (data_timestamp < millis) { 
        std::cout << "Hello"; 
    } else { 
        std::cout << "World"; 
    }

    return 0;
}

I will run this code on Ubuntu 12.04. When I compile it while running make install, it gives me this exception -

warning: âautoâ changes meaning in C++11; please remove it [-Wc++0x-compat]
error: ânowâ does not name a type
warning: âautoâ changes meaning in C++11; please remove it [-Wc++0x-compat]
âtwoWeeksâ does not name a type
warning: âautoâ changes meaning in C++11; please remove it [-Wc++0x-compat]
error: âlastTwoWeeksâ does not name a type
warning: âautoâ changes meaning in C++11; please remove it [-Wc++0x-compat]
error: âmillisâ does not name a type
error: âmillisâ was not declared in this scope

, C++11. , , ++, , ++ 11, . , , ++ 11?

: -

, -

struct timeval tp;
gettimeofday(&tp, NULL);
uint64_t current_ms = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds
+4
1

auto ( ) ++ 11. -std=c++11.

+13

All Articles