Thread: error C2143 missing ';'...

  1. #1
    Registered User
    Join Date
    Nov 2018
    Posts
    17

    error C2143 missing ';'...

    Hi all,

    i am using Microsoft Visual C++ 2010 Express

    i am sure, a super easy question. i am just learning C++...and i am already stuck with this error...here the simple program

    Code:
    #include <iostream>
    using namespace std;
    int main() 
    {
        int ai {5}; // Error : Missing ';' before {
        cout << ai;
        return 0;
    }
    i admit i never used such initialisation and never heard of it so far, i used to write
    Code:
    int ai = 5
    why is the compiler complaining.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    26,943
    The syntax you're trying to use was introduced in the 2011 edition of the C++ standard, i.e., your compiler is too old.
    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

  3. #3
    Registered User
    Join Date
    Nov 2018
    Posts
    17
    oook. Understood. thanks.

    is there an advantage of the new syntax again the old one?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    26,943
    Quote Originally Posted by Scatman
    is there an advantage of the new syntax again the old one?
    It's a bit old and so might be outdated for C++14 and C++17 as I vaguely recall some technical change in this area, but it's still a good overview: GotW #1 Solution: Variable Initialization – or Is It?
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP NEEDED!!! Error C2143
    By shamanthemain in forum C Programming
    Replies: 5
    Last Post: 08-21-2013, 11:35 AM
  2. C2143 errors
    By stormi in forum C Programming
    Replies: 2
    Last Post: 11-14-2009, 11:32 AM
  3. error C2143: syntax error : missing ')' before ';'
    By steve1_rm in forum C Programming
    Replies: 4
    Last Post: 05-14-2008, 11:06 AM
  4. Help with a missing ';' error
    By Mystic_Skies in forum C++ Programming
    Replies: 4
    Last Post: 09-01-2005, 08:38 AM

Tags for this Thread