I'm doing a course but the things the lecturer says works don't












3















I have recently gotten into programming and decided to learn C++. I took advantage of the sale on Udemy and bought three courses there, one for beginners on C++, one for game-making and one for Blender.



I started doing the course for beginners, the lecturer said that he would use Code::Blocks but that any other IDE would be fine so I downloaded Visual Studio 2017 because that's what the game-making course used. But when I do exactly as the lecturer says (and writes), the code won't compile correctly.



Here is an example:



What the lecturer wrote and got to work on his computer



#include <iostream> 

using namespace std;

main()
{
cout << "Hello world! :-)";

}


What I figured out would work after some googling



#include <pch.h>
#include <iostream>
using std::cout;

int main()
{
cout << "Hello world! :-)";
}


And my question to those who are experienced is: What is the difference between Code::Blocks and Visual Studio 2017? What is different in that case? Will I even be able to use this course to learn?



Thanks in advance!



edit: edited in a missing # in the lecturer's code










share|improve this question















migrated from superuser.com Jan 10 at 15:29


This question came from our site for computer enthusiasts and power users.



















  • Your professor wrote C++ code, by using Visual Studio and the syntax, you actually wrote Visual C++ code. You are using an entirely different compiler then your professor. You should configure Visual Studio to use the same C++ compiler, I should point out, Visual Studio supports several different versions of the C++ standard, so it absolutely should work with the first code block. However, questions which ask if you will be able to use this course, are not within our scope. It isn't something anyone can answer at any Stack Exchange community and certainly not here at Super User.

    – Security Hound
    Jan 10 at 15:27






  • 3





    Precompiled headers

    – Igor Tandetnik
    Jan 10 at 15:31











  • If you want to write a regular console app in VS2017 use Create New Project -> Visual C++ -> Windows Desktop -> Windows Desktop Wizzard and then make sure is says Console Application in the Application type and uncheck Precompiled Headers and Security Development Lifecycle and do check empty project.

    – NathanOliver
    Jan 10 at 15:34






  • 3





    @FrançoisAndrieux: Declaring a function with no return type has never been valid C++, but it is valid C89.

    – You
    Jan 10 at 15:36






  • 1





    Normally I would use "" for headers in the solution or project and <> for system or external headers so #include <pch.h> would be #include "pch.h". With that said either way will work in VS.

    – drescherjm
    Jan 10 at 15:42


















3















I have recently gotten into programming and decided to learn C++. I took advantage of the sale on Udemy and bought three courses there, one for beginners on C++, one for game-making and one for Blender.



I started doing the course for beginners, the lecturer said that he would use Code::Blocks but that any other IDE would be fine so I downloaded Visual Studio 2017 because that's what the game-making course used. But when I do exactly as the lecturer says (and writes), the code won't compile correctly.



Here is an example:



What the lecturer wrote and got to work on his computer



#include <iostream> 

using namespace std;

main()
{
cout << "Hello world! :-)";

}


What I figured out would work after some googling



#include <pch.h>
#include <iostream>
using std::cout;

int main()
{
cout << "Hello world! :-)";
}


And my question to those who are experienced is: What is the difference between Code::Blocks and Visual Studio 2017? What is different in that case? Will I even be able to use this course to learn?



Thanks in advance!



edit: edited in a missing # in the lecturer's code










share|improve this question















migrated from superuser.com Jan 10 at 15:29


This question came from our site for computer enthusiasts and power users.



















  • Your professor wrote C++ code, by using Visual Studio and the syntax, you actually wrote Visual C++ code. You are using an entirely different compiler then your professor. You should configure Visual Studio to use the same C++ compiler, I should point out, Visual Studio supports several different versions of the C++ standard, so it absolutely should work with the first code block. However, questions which ask if you will be able to use this course, are not within our scope. It isn't something anyone can answer at any Stack Exchange community and certainly not here at Super User.

    – Security Hound
    Jan 10 at 15:27






  • 3





    Precompiled headers

    – Igor Tandetnik
    Jan 10 at 15:31











  • If you want to write a regular console app in VS2017 use Create New Project -> Visual C++ -> Windows Desktop -> Windows Desktop Wizzard and then make sure is says Console Application in the Application type and uncheck Precompiled Headers and Security Development Lifecycle and do check empty project.

    – NathanOliver
    Jan 10 at 15:34






  • 3





    @FrançoisAndrieux: Declaring a function with no return type has never been valid C++, but it is valid C89.

    – You
    Jan 10 at 15:36






  • 1





    Normally I would use "" for headers in the solution or project and <> for system or external headers so #include <pch.h> would be #include "pch.h". With that said either way will work in VS.

    – drescherjm
    Jan 10 at 15:42
















3












3








3








I have recently gotten into programming and decided to learn C++. I took advantage of the sale on Udemy and bought three courses there, one for beginners on C++, one for game-making and one for Blender.



I started doing the course for beginners, the lecturer said that he would use Code::Blocks but that any other IDE would be fine so I downloaded Visual Studio 2017 because that's what the game-making course used. But when I do exactly as the lecturer says (and writes), the code won't compile correctly.



Here is an example:



What the lecturer wrote and got to work on his computer



#include <iostream> 

using namespace std;

main()
{
cout << "Hello world! :-)";

}


What I figured out would work after some googling



#include <pch.h>
#include <iostream>
using std::cout;

int main()
{
cout << "Hello world! :-)";
}


And my question to those who are experienced is: What is the difference between Code::Blocks and Visual Studio 2017? What is different in that case? Will I even be able to use this course to learn?



Thanks in advance!



edit: edited in a missing # in the lecturer's code










share|improve this question
















I have recently gotten into programming and decided to learn C++. I took advantage of the sale on Udemy and bought three courses there, one for beginners on C++, one for game-making and one for Blender.



I started doing the course for beginners, the lecturer said that he would use Code::Blocks but that any other IDE would be fine so I downloaded Visual Studio 2017 because that's what the game-making course used. But when I do exactly as the lecturer says (and writes), the code won't compile correctly.



Here is an example:



What the lecturer wrote and got to work on his computer



#include <iostream> 

using namespace std;

main()
{
cout << "Hello world! :-)";

}


What I figured out would work after some googling



#include <pch.h>
#include <iostream>
using std::cout;

int main()
{
cout << "Hello world! :-)";
}


And my question to those who are experienced is: What is the difference between Code::Blocks and Visual Studio 2017? What is different in that case? Will I even be able to use this course to learn?



Thanks in advance!



edit: edited in a missing # in the lecturer's code







visual-studio c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 11 at 16:29







Wilmer Jonsson

















asked Jan 10 at 15:19









Wilmer JonssonWilmer Jonsson

192




192




migrated from superuser.com Jan 10 at 15:29


This question came from our site for computer enthusiasts and power users.









migrated from superuser.com Jan 10 at 15:29


This question came from our site for computer enthusiasts and power users.















  • Your professor wrote C++ code, by using Visual Studio and the syntax, you actually wrote Visual C++ code. You are using an entirely different compiler then your professor. You should configure Visual Studio to use the same C++ compiler, I should point out, Visual Studio supports several different versions of the C++ standard, so it absolutely should work with the first code block. However, questions which ask if you will be able to use this course, are not within our scope. It isn't something anyone can answer at any Stack Exchange community and certainly not here at Super User.

    – Security Hound
    Jan 10 at 15:27






  • 3





    Precompiled headers

    – Igor Tandetnik
    Jan 10 at 15:31











  • If you want to write a regular console app in VS2017 use Create New Project -> Visual C++ -> Windows Desktop -> Windows Desktop Wizzard and then make sure is says Console Application in the Application type and uncheck Precompiled Headers and Security Development Lifecycle and do check empty project.

    – NathanOliver
    Jan 10 at 15:34






  • 3





    @FrançoisAndrieux: Declaring a function with no return type has never been valid C++, but it is valid C89.

    – You
    Jan 10 at 15:36






  • 1





    Normally I would use "" for headers in the solution or project and <> for system or external headers so #include <pch.h> would be #include "pch.h". With that said either way will work in VS.

    – drescherjm
    Jan 10 at 15:42





















  • Your professor wrote C++ code, by using Visual Studio and the syntax, you actually wrote Visual C++ code. You are using an entirely different compiler then your professor. You should configure Visual Studio to use the same C++ compiler, I should point out, Visual Studio supports several different versions of the C++ standard, so it absolutely should work with the first code block. However, questions which ask if you will be able to use this course, are not within our scope. It isn't something anyone can answer at any Stack Exchange community and certainly not here at Super User.

    – Security Hound
    Jan 10 at 15:27






  • 3





    Precompiled headers

    – Igor Tandetnik
    Jan 10 at 15:31











  • If you want to write a regular console app in VS2017 use Create New Project -> Visual C++ -> Windows Desktop -> Windows Desktop Wizzard and then make sure is says Console Application in the Application type and uncheck Precompiled Headers and Security Development Lifecycle and do check empty project.

    – NathanOliver
    Jan 10 at 15:34






  • 3





    @FrançoisAndrieux: Declaring a function with no return type has never been valid C++, but it is valid C89.

    – You
    Jan 10 at 15:36






  • 1





    Normally I would use "" for headers in the solution or project and <> for system or external headers so #include <pch.h> would be #include "pch.h". With that said either way will work in VS.

    – drescherjm
    Jan 10 at 15:42



















Your professor wrote C++ code, by using Visual Studio and the syntax, you actually wrote Visual C++ code. You are using an entirely different compiler then your professor. You should configure Visual Studio to use the same C++ compiler, I should point out, Visual Studio supports several different versions of the C++ standard, so it absolutely should work with the first code block. However, questions which ask if you will be able to use this course, are not within our scope. It isn't something anyone can answer at any Stack Exchange community and certainly not here at Super User.

– Security Hound
Jan 10 at 15:27





Your professor wrote C++ code, by using Visual Studio and the syntax, you actually wrote Visual C++ code. You are using an entirely different compiler then your professor. You should configure Visual Studio to use the same C++ compiler, I should point out, Visual Studio supports several different versions of the C++ standard, so it absolutely should work with the first code block. However, questions which ask if you will be able to use this course, are not within our scope. It isn't something anyone can answer at any Stack Exchange community and certainly not here at Super User.

– Security Hound
Jan 10 at 15:27




3




3





Precompiled headers

– Igor Tandetnik
Jan 10 at 15:31





Precompiled headers

– Igor Tandetnik
Jan 10 at 15:31













If you want to write a regular console app in VS2017 use Create New Project -> Visual C++ -> Windows Desktop -> Windows Desktop Wizzard and then make sure is says Console Application in the Application type and uncheck Precompiled Headers and Security Development Lifecycle and do check empty project.

– NathanOliver
Jan 10 at 15:34





If you want to write a regular console app in VS2017 use Create New Project -> Visual C++ -> Windows Desktop -> Windows Desktop Wizzard and then make sure is says Console Application in the Application type and uncheck Precompiled Headers and Security Development Lifecycle and do check empty project.

– NathanOliver
Jan 10 at 15:34




3




3





@FrançoisAndrieux: Declaring a function with no return type has never been valid C++, but it is valid C89.

– You
Jan 10 at 15:36





@FrançoisAndrieux: Declaring a function with no return type has never been valid C++, but it is valid C89.

– You
Jan 10 at 15:36




1




1





Normally I would use "" for headers in the solution or project and <> for system or external headers so #include <pch.h> would be #include "pch.h". With that said either way will work in VS.

– drescherjm
Jan 10 at 15:42







Normally I would use "" for headers in the solution or project and <> for system or external headers so #include <pch.h> would be #include "pch.h". With that said either way will work in VS.

– drescherjm
Jan 10 at 15:42














3 Answers
3






active

oldest

votes


















4















  • #include <pch.h>:

    See Gabriel's answer.


  • include <iostream> vs #include <iostream>:

    The former is plain wrong. It has to be #include with the #.


  • using namespace std; vs using std::cout;:

    While neither is particularly good practice, both should do the same thing here. If you write neither of them, you will have to write std::cout << ... instead of only cout << ... - that seems annoying but is something you should get used to if you want to eventually be a serious C++ programmer. See also Why is "using namespace std" considered bad practice?.


  • main() vs int main():

    This is not something that Code::Blocks should allow because it is not correct C++. main should always return int.



Overall you seem to have hit an unfortunate number of differences between environments/compilers on this basic example already. However, neither your course nor VS2017 is wrong so far, so I recommend you keep using them. If something that your lecturer writes won't work for in a different environment, it's probably a bad idea to write that kind of code in the first place. And they did make several mistakes in this simple example.



PS: I strongly recommend enabling warnings, because they may tell you when you do something wrong in a more subtle way. There are many mistakes (of the "shooting yourself in the foot" kind) that the compiler is not required to stop you from making, but if you ask to be stopped (by heeding warnings) it will help you.






share|improve this answer

































    3














    Using Visual Studio should be okay as long as you disable precompiled headers and your tutorial uses standard-compliant code.



    About precompiled headers :



    Visual Studio enables pre-compiled headers by default in a C++ command line program. This means that in your project, it'll by default force you to use a precompiled header in the first line of your source code (pch.h here).
    By disabling them, you can almost* make the first snippet work in VS. To do this, select your project, go to the "Project->Properties" menu, then to the "Configuration Properties -> C/C++ -> Precompiled Headers" section, then change the "Precompiled Header" setting to "Not Using Precompiled Headers" option (this applies to VS 2012, applying this to other versions of VS should be easy).



    If you want to avoid this in the future, you can create an empty project when setting up your project in VS.



    See also : http://msdn.microsoft.com/en-us/library/h9x39eaw%28v=vs.71%29.aspx, How to avoid precompiled headers



    * : The first snippet won't actually work since the declaration of main is not correct C++, only C (see https://en.cppreference.com/w/cpp/language/main_function, What is the proper declaration of main?)






    share|improve this answer

































      3














      To your actual question, VS will be fine for your course, although I'm still puzzled by the lecturer's original version of this code.



      However, it's really useful to take the time to understand what all your changes did, and why they fixed your problem. Maybe you did this already - that's just not the impression I got from the phrase




      What I figured out would work after some googling





      • when you get a compile error or warning, read it and try to understand it.

      • if you don't understand the error - and this is normal, certainly while you're learning - then hacking on the code until it works is perfectly fine. At least sometimes it's quicker, and the knowledge that you made progress is its own reward.

      • if hacking away at the code with the internet at your disposal doesn't get a solution, you'll just have to study the error message more. Turning all compiler errors and warnings on, and trying multiple compilers can both help - even if they all fail, the messages might be more useful. (I often find clang has useful errors, and godbolt.org is super helpful).


      • if hacking away at the code does get a solution, you should still try and understand why. Now you can see what you changed, look at the original error and try to understand why your changes fixed it. If you made multiple changes, were they all really necessary? Do you understand what they all did, and why?



        If you do this, you can fix the next related problem faster, rather than going through the whole trial-and-error process again. You can even write better code that avoids the problem in the first place.



        This is the part that actually constitutes learning, which is why I'm making a point of addressing it.






      The important fix was changing the lines



      include <iostream>

      main()


      to



      #include <iostream>

      int main()


      because the former aren't legal C++. If your lecturer really wrote exactly that and you didn't somehow mis-copy, then I have no idea why their example worked.



      The Visual Studio-specific stuff is the precompiled header, as described in Gabriel's answer.



      But the remaining change is essentially cosmetic. Replacing:



      using namespace std;


      with



      using std::cout;


      Doesn't affect anything in your code, and just using



        std::cout << "Hello world! :-)";


      (with no using at all) would work just as well.






      share|improve this answer


























      • It's safe to assume that these were more than "random code permutations". In fact, I'd bet that one of the error messages (use of undeclared identifier 'cout') that was googled at some point led to an answer along the lines of "you forgot using std::cout". I find the last paragraph unnecessarily patronising, especially given how they already did manage to fix all these errors with no more than one incidental change.

        – Max Langhof
        Jan 10 at 17:01













      • The problem if that if you're introducing incidental changes, that means you don't know which changes were important, which means you don't know why they worked or how to avoid the problem in future.

        – Useless
        Jan 10 at 17:10











      • The key point isn't that you should never hack on something until it works - you can't either learn or sustain your motivation in a vacuum - but that you need to learn to read the error message, and when your code finally works, it's very useful to sit down and understand why.

        – Useless
        Jan 10 at 17:12











      • That's all true, but you are currently inferring that the asker did none of that, simply because they didn't revert that one change. They probably did realize that the two usings were equivalent in the process of getting the code to compile (because the change did not change the error message), at which point it's simpler to leave it there than to revert it - and why would you waste the effort if you have 3 other compiler messages left to worry about? I don't think the scolding (that's what it feels like to me as an unrelated third) is appropriate here.

        – Max Langhof
        Jan 10 at 17:18













      • Possibly! I might be reading too much into the phrase what I figured out would work after some googling, but that's how it comes across to me. The question doesn't suggest any particular understanding of what the changes mean, at least. Anyway, it's not meant to scold, but to reinforce the habit of trying to understand.

        – Useless
        Jan 10 at 17:28













      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54131940%2fim-doing-a-course-but-the-things-the-lecturer-says-works-dont%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4















      • #include <pch.h>:

        See Gabriel's answer.


      • include <iostream> vs #include <iostream>:

        The former is plain wrong. It has to be #include with the #.


      • using namespace std; vs using std::cout;:

        While neither is particularly good practice, both should do the same thing here. If you write neither of them, you will have to write std::cout << ... instead of only cout << ... - that seems annoying but is something you should get used to if you want to eventually be a serious C++ programmer. See also Why is "using namespace std" considered bad practice?.


      • main() vs int main():

        This is not something that Code::Blocks should allow because it is not correct C++. main should always return int.



      Overall you seem to have hit an unfortunate number of differences between environments/compilers on this basic example already. However, neither your course nor VS2017 is wrong so far, so I recommend you keep using them. If something that your lecturer writes won't work for in a different environment, it's probably a bad idea to write that kind of code in the first place. And they did make several mistakes in this simple example.



      PS: I strongly recommend enabling warnings, because they may tell you when you do something wrong in a more subtle way. There are many mistakes (of the "shooting yourself in the foot" kind) that the compiler is not required to stop you from making, but if you ask to be stopped (by heeding warnings) it will help you.






      share|improve this answer






























        4















        • #include <pch.h>:

          See Gabriel's answer.


        • include <iostream> vs #include <iostream>:

          The former is plain wrong. It has to be #include with the #.


        • using namespace std; vs using std::cout;:

          While neither is particularly good practice, both should do the same thing here. If you write neither of them, you will have to write std::cout << ... instead of only cout << ... - that seems annoying but is something you should get used to if you want to eventually be a serious C++ programmer. See also Why is "using namespace std" considered bad practice?.


        • main() vs int main():

          This is not something that Code::Blocks should allow because it is not correct C++. main should always return int.



        Overall you seem to have hit an unfortunate number of differences between environments/compilers on this basic example already. However, neither your course nor VS2017 is wrong so far, so I recommend you keep using them. If something that your lecturer writes won't work for in a different environment, it's probably a bad idea to write that kind of code in the first place. And they did make several mistakes in this simple example.



        PS: I strongly recommend enabling warnings, because they may tell you when you do something wrong in a more subtle way. There are many mistakes (of the "shooting yourself in the foot" kind) that the compiler is not required to stop you from making, but if you ask to be stopped (by heeding warnings) it will help you.






        share|improve this answer




























          4












          4








          4








          • #include <pch.h>:

            See Gabriel's answer.


          • include <iostream> vs #include <iostream>:

            The former is plain wrong. It has to be #include with the #.


          • using namespace std; vs using std::cout;:

            While neither is particularly good practice, both should do the same thing here. If you write neither of them, you will have to write std::cout << ... instead of only cout << ... - that seems annoying but is something you should get used to if you want to eventually be a serious C++ programmer. See also Why is "using namespace std" considered bad practice?.


          • main() vs int main():

            This is not something that Code::Blocks should allow because it is not correct C++. main should always return int.



          Overall you seem to have hit an unfortunate number of differences between environments/compilers on this basic example already. However, neither your course nor VS2017 is wrong so far, so I recommend you keep using them. If something that your lecturer writes won't work for in a different environment, it's probably a bad idea to write that kind of code in the first place. And they did make several mistakes in this simple example.



          PS: I strongly recommend enabling warnings, because they may tell you when you do something wrong in a more subtle way. There are many mistakes (of the "shooting yourself in the foot" kind) that the compiler is not required to stop you from making, but if you ask to be stopped (by heeding warnings) it will help you.






          share|improve this answer
















          • #include <pch.h>:

            See Gabriel's answer.


          • include <iostream> vs #include <iostream>:

            The former is plain wrong. It has to be #include with the #.


          • using namespace std; vs using std::cout;:

            While neither is particularly good practice, both should do the same thing here. If you write neither of them, you will have to write std::cout << ... instead of only cout << ... - that seems annoying but is something you should get used to if you want to eventually be a serious C++ programmer. See also Why is "using namespace std" considered bad practice?.


          • main() vs int main():

            This is not something that Code::Blocks should allow because it is not correct C++. main should always return int.



          Overall you seem to have hit an unfortunate number of differences between environments/compilers on this basic example already. However, neither your course nor VS2017 is wrong so far, so I recommend you keep using them. If something that your lecturer writes won't work for in a different environment, it's probably a bad idea to write that kind of code in the first place. And they did make several mistakes in this simple example.



          PS: I strongly recommend enabling warnings, because they may tell you when you do something wrong in a more subtle way. There are many mistakes (of the "shooting yourself in the foot" kind) that the compiler is not required to stop you from making, but if you ask to be stopped (by heeding warnings) it will help you.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 10 at 15:57

























          answered Jan 10 at 15:52









          Max LanghofMax Langhof

          9,9391838




          9,9391838

























              3














              Using Visual Studio should be okay as long as you disable precompiled headers and your tutorial uses standard-compliant code.



              About precompiled headers :



              Visual Studio enables pre-compiled headers by default in a C++ command line program. This means that in your project, it'll by default force you to use a precompiled header in the first line of your source code (pch.h here).
              By disabling them, you can almost* make the first snippet work in VS. To do this, select your project, go to the "Project->Properties" menu, then to the "Configuration Properties -> C/C++ -> Precompiled Headers" section, then change the "Precompiled Header" setting to "Not Using Precompiled Headers" option (this applies to VS 2012, applying this to other versions of VS should be easy).



              If you want to avoid this in the future, you can create an empty project when setting up your project in VS.



              See also : http://msdn.microsoft.com/en-us/library/h9x39eaw%28v=vs.71%29.aspx, How to avoid precompiled headers



              * : The first snippet won't actually work since the declaration of main is not correct C++, only C (see https://en.cppreference.com/w/cpp/language/main_function, What is the proper declaration of main?)






              share|improve this answer






























                3














                Using Visual Studio should be okay as long as you disable precompiled headers and your tutorial uses standard-compliant code.



                About precompiled headers :



                Visual Studio enables pre-compiled headers by default in a C++ command line program. This means that in your project, it'll by default force you to use a precompiled header in the first line of your source code (pch.h here).
                By disabling them, you can almost* make the first snippet work in VS. To do this, select your project, go to the "Project->Properties" menu, then to the "Configuration Properties -> C/C++ -> Precompiled Headers" section, then change the "Precompiled Header" setting to "Not Using Precompiled Headers" option (this applies to VS 2012, applying this to other versions of VS should be easy).



                If you want to avoid this in the future, you can create an empty project when setting up your project in VS.



                See also : http://msdn.microsoft.com/en-us/library/h9x39eaw%28v=vs.71%29.aspx, How to avoid precompiled headers



                * : The first snippet won't actually work since the declaration of main is not correct C++, only C (see https://en.cppreference.com/w/cpp/language/main_function, What is the proper declaration of main?)






                share|improve this answer




























                  3












                  3








                  3







                  Using Visual Studio should be okay as long as you disable precompiled headers and your tutorial uses standard-compliant code.



                  About precompiled headers :



                  Visual Studio enables pre-compiled headers by default in a C++ command line program. This means that in your project, it'll by default force you to use a precompiled header in the first line of your source code (pch.h here).
                  By disabling them, you can almost* make the first snippet work in VS. To do this, select your project, go to the "Project->Properties" menu, then to the "Configuration Properties -> C/C++ -> Precompiled Headers" section, then change the "Precompiled Header" setting to "Not Using Precompiled Headers" option (this applies to VS 2012, applying this to other versions of VS should be easy).



                  If you want to avoid this in the future, you can create an empty project when setting up your project in VS.



                  See also : http://msdn.microsoft.com/en-us/library/h9x39eaw%28v=vs.71%29.aspx, How to avoid precompiled headers



                  * : The first snippet won't actually work since the declaration of main is not correct C++, only C (see https://en.cppreference.com/w/cpp/language/main_function, What is the proper declaration of main?)






                  share|improve this answer















                  Using Visual Studio should be okay as long as you disable precompiled headers and your tutorial uses standard-compliant code.



                  About precompiled headers :



                  Visual Studio enables pre-compiled headers by default in a C++ command line program. This means that in your project, it'll by default force you to use a precompiled header in the first line of your source code (pch.h here).
                  By disabling them, you can almost* make the first snippet work in VS. To do this, select your project, go to the "Project->Properties" menu, then to the "Configuration Properties -> C/C++ -> Precompiled Headers" section, then change the "Precompiled Header" setting to "Not Using Precompiled Headers" option (this applies to VS 2012, applying this to other versions of VS should be easy).



                  If you want to avoid this in the future, you can create an empty project when setting up your project in VS.



                  See also : http://msdn.microsoft.com/en-us/library/h9x39eaw%28v=vs.71%29.aspx, How to avoid precompiled headers



                  * : The first snippet won't actually work since the declaration of main is not correct C++, only C (see https://en.cppreference.com/w/cpp/language/main_function, What is the proper declaration of main?)







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 10 at 15:45

























                  answered Jan 10 at 15:38









                  Gabriel RavierGabriel Ravier

                  133212




                  133212























                      3














                      To your actual question, VS will be fine for your course, although I'm still puzzled by the lecturer's original version of this code.



                      However, it's really useful to take the time to understand what all your changes did, and why they fixed your problem. Maybe you did this already - that's just not the impression I got from the phrase




                      What I figured out would work after some googling





                      • when you get a compile error or warning, read it and try to understand it.

                      • if you don't understand the error - and this is normal, certainly while you're learning - then hacking on the code until it works is perfectly fine. At least sometimes it's quicker, and the knowledge that you made progress is its own reward.

                      • if hacking away at the code with the internet at your disposal doesn't get a solution, you'll just have to study the error message more. Turning all compiler errors and warnings on, and trying multiple compilers can both help - even if they all fail, the messages might be more useful. (I often find clang has useful errors, and godbolt.org is super helpful).


                      • if hacking away at the code does get a solution, you should still try and understand why. Now you can see what you changed, look at the original error and try to understand why your changes fixed it. If you made multiple changes, were they all really necessary? Do you understand what they all did, and why?



                        If you do this, you can fix the next related problem faster, rather than going through the whole trial-and-error process again. You can even write better code that avoids the problem in the first place.



                        This is the part that actually constitutes learning, which is why I'm making a point of addressing it.






                      The important fix was changing the lines



                      include <iostream>

                      main()


                      to



                      #include <iostream>

                      int main()


                      because the former aren't legal C++. If your lecturer really wrote exactly that and you didn't somehow mis-copy, then I have no idea why their example worked.



                      The Visual Studio-specific stuff is the precompiled header, as described in Gabriel's answer.



                      But the remaining change is essentially cosmetic. Replacing:



                      using namespace std;


                      with



                      using std::cout;


                      Doesn't affect anything in your code, and just using



                        std::cout << "Hello world! :-)";


                      (with no using at all) would work just as well.






                      share|improve this answer


























                      • It's safe to assume that these were more than "random code permutations". In fact, I'd bet that one of the error messages (use of undeclared identifier 'cout') that was googled at some point led to an answer along the lines of "you forgot using std::cout". I find the last paragraph unnecessarily patronising, especially given how they already did manage to fix all these errors with no more than one incidental change.

                        – Max Langhof
                        Jan 10 at 17:01













                      • The problem if that if you're introducing incidental changes, that means you don't know which changes were important, which means you don't know why they worked or how to avoid the problem in future.

                        – Useless
                        Jan 10 at 17:10











                      • The key point isn't that you should never hack on something until it works - you can't either learn or sustain your motivation in a vacuum - but that you need to learn to read the error message, and when your code finally works, it's very useful to sit down and understand why.

                        – Useless
                        Jan 10 at 17:12











                      • That's all true, but you are currently inferring that the asker did none of that, simply because they didn't revert that one change. They probably did realize that the two usings were equivalent in the process of getting the code to compile (because the change did not change the error message), at which point it's simpler to leave it there than to revert it - and why would you waste the effort if you have 3 other compiler messages left to worry about? I don't think the scolding (that's what it feels like to me as an unrelated third) is appropriate here.

                        – Max Langhof
                        Jan 10 at 17:18













                      • Possibly! I might be reading too much into the phrase what I figured out would work after some googling, but that's how it comes across to me. The question doesn't suggest any particular understanding of what the changes mean, at least. Anyway, it's not meant to scold, but to reinforce the habit of trying to understand.

                        – Useless
                        Jan 10 at 17:28


















                      3














                      To your actual question, VS will be fine for your course, although I'm still puzzled by the lecturer's original version of this code.



                      However, it's really useful to take the time to understand what all your changes did, and why they fixed your problem. Maybe you did this already - that's just not the impression I got from the phrase




                      What I figured out would work after some googling





                      • when you get a compile error or warning, read it and try to understand it.

                      • if you don't understand the error - and this is normal, certainly while you're learning - then hacking on the code until it works is perfectly fine. At least sometimes it's quicker, and the knowledge that you made progress is its own reward.

                      • if hacking away at the code with the internet at your disposal doesn't get a solution, you'll just have to study the error message more. Turning all compiler errors and warnings on, and trying multiple compilers can both help - even if they all fail, the messages might be more useful. (I often find clang has useful errors, and godbolt.org is super helpful).


                      • if hacking away at the code does get a solution, you should still try and understand why. Now you can see what you changed, look at the original error and try to understand why your changes fixed it. If you made multiple changes, were they all really necessary? Do you understand what they all did, and why?



                        If you do this, you can fix the next related problem faster, rather than going through the whole trial-and-error process again. You can even write better code that avoids the problem in the first place.



                        This is the part that actually constitutes learning, which is why I'm making a point of addressing it.






                      The important fix was changing the lines



                      include <iostream>

                      main()


                      to



                      #include <iostream>

                      int main()


                      because the former aren't legal C++. If your lecturer really wrote exactly that and you didn't somehow mis-copy, then I have no idea why their example worked.



                      The Visual Studio-specific stuff is the precompiled header, as described in Gabriel's answer.



                      But the remaining change is essentially cosmetic. Replacing:



                      using namespace std;


                      with



                      using std::cout;


                      Doesn't affect anything in your code, and just using



                        std::cout << "Hello world! :-)";


                      (with no using at all) would work just as well.






                      share|improve this answer


























                      • It's safe to assume that these were more than "random code permutations". In fact, I'd bet that one of the error messages (use of undeclared identifier 'cout') that was googled at some point led to an answer along the lines of "you forgot using std::cout". I find the last paragraph unnecessarily patronising, especially given how they already did manage to fix all these errors with no more than one incidental change.

                        – Max Langhof
                        Jan 10 at 17:01













                      • The problem if that if you're introducing incidental changes, that means you don't know which changes were important, which means you don't know why they worked or how to avoid the problem in future.

                        – Useless
                        Jan 10 at 17:10











                      • The key point isn't that you should never hack on something until it works - you can't either learn or sustain your motivation in a vacuum - but that you need to learn to read the error message, and when your code finally works, it's very useful to sit down and understand why.

                        – Useless
                        Jan 10 at 17:12











                      • That's all true, but you are currently inferring that the asker did none of that, simply because they didn't revert that one change. They probably did realize that the two usings were equivalent in the process of getting the code to compile (because the change did not change the error message), at which point it's simpler to leave it there than to revert it - and why would you waste the effort if you have 3 other compiler messages left to worry about? I don't think the scolding (that's what it feels like to me as an unrelated third) is appropriate here.

                        – Max Langhof
                        Jan 10 at 17:18













                      • Possibly! I might be reading too much into the phrase what I figured out would work after some googling, but that's how it comes across to me. The question doesn't suggest any particular understanding of what the changes mean, at least. Anyway, it's not meant to scold, but to reinforce the habit of trying to understand.

                        – Useless
                        Jan 10 at 17:28
















                      3












                      3








                      3







                      To your actual question, VS will be fine for your course, although I'm still puzzled by the lecturer's original version of this code.



                      However, it's really useful to take the time to understand what all your changes did, and why they fixed your problem. Maybe you did this already - that's just not the impression I got from the phrase




                      What I figured out would work after some googling





                      • when you get a compile error or warning, read it and try to understand it.

                      • if you don't understand the error - and this is normal, certainly while you're learning - then hacking on the code until it works is perfectly fine. At least sometimes it's quicker, and the knowledge that you made progress is its own reward.

                      • if hacking away at the code with the internet at your disposal doesn't get a solution, you'll just have to study the error message more. Turning all compiler errors and warnings on, and trying multiple compilers can both help - even if they all fail, the messages might be more useful. (I often find clang has useful errors, and godbolt.org is super helpful).


                      • if hacking away at the code does get a solution, you should still try and understand why. Now you can see what you changed, look at the original error and try to understand why your changes fixed it. If you made multiple changes, were they all really necessary? Do you understand what they all did, and why?



                        If you do this, you can fix the next related problem faster, rather than going through the whole trial-and-error process again. You can even write better code that avoids the problem in the first place.



                        This is the part that actually constitutes learning, which is why I'm making a point of addressing it.






                      The important fix was changing the lines



                      include <iostream>

                      main()


                      to



                      #include <iostream>

                      int main()


                      because the former aren't legal C++. If your lecturer really wrote exactly that and you didn't somehow mis-copy, then I have no idea why their example worked.



                      The Visual Studio-specific stuff is the precompiled header, as described in Gabriel's answer.



                      But the remaining change is essentially cosmetic. Replacing:



                      using namespace std;


                      with



                      using std::cout;


                      Doesn't affect anything in your code, and just using



                        std::cout << "Hello world! :-)";


                      (with no using at all) would work just as well.






                      share|improve this answer















                      To your actual question, VS will be fine for your course, although I'm still puzzled by the lecturer's original version of this code.



                      However, it's really useful to take the time to understand what all your changes did, and why they fixed your problem. Maybe you did this already - that's just not the impression I got from the phrase




                      What I figured out would work after some googling





                      • when you get a compile error or warning, read it and try to understand it.

                      • if you don't understand the error - and this is normal, certainly while you're learning - then hacking on the code until it works is perfectly fine. At least sometimes it's quicker, and the knowledge that you made progress is its own reward.

                      • if hacking away at the code with the internet at your disposal doesn't get a solution, you'll just have to study the error message more. Turning all compiler errors and warnings on, and trying multiple compilers can both help - even if they all fail, the messages might be more useful. (I often find clang has useful errors, and godbolt.org is super helpful).


                      • if hacking away at the code does get a solution, you should still try and understand why. Now you can see what you changed, look at the original error and try to understand why your changes fixed it. If you made multiple changes, were they all really necessary? Do you understand what they all did, and why?



                        If you do this, you can fix the next related problem faster, rather than going through the whole trial-and-error process again. You can even write better code that avoids the problem in the first place.



                        This is the part that actually constitutes learning, which is why I'm making a point of addressing it.






                      The important fix was changing the lines



                      include <iostream>

                      main()


                      to



                      #include <iostream>

                      int main()


                      because the former aren't legal C++. If your lecturer really wrote exactly that and you didn't somehow mis-copy, then I have no idea why their example worked.



                      The Visual Studio-specific stuff is the precompiled header, as described in Gabriel's answer.



                      But the remaining change is essentially cosmetic. Replacing:



                      using namespace std;


                      with



                      using std::cout;


                      Doesn't affect anything in your code, and just using



                        std::cout << "Hello world! :-)";


                      (with no using at all) would work just as well.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jan 10 at 17:37

























                      answered Jan 10 at 16:00









                      UselessUseless

                      43.8k45394




                      43.8k45394













                      • It's safe to assume that these were more than "random code permutations". In fact, I'd bet that one of the error messages (use of undeclared identifier 'cout') that was googled at some point led to an answer along the lines of "you forgot using std::cout". I find the last paragraph unnecessarily patronising, especially given how they already did manage to fix all these errors with no more than one incidental change.

                        – Max Langhof
                        Jan 10 at 17:01













                      • The problem if that if you're introducing incidental changes, that means you don't know which changes were important, which means you don't know why they worked or how to avoid the problem in future.

                        – Useless
                        Jan 10 at 17:10











                      • The key point isn't that you should never hack on something until it works - you can't either learn or sustain your motivation in a vacuum - but that you need to learn to read the error message, and when your code finally works, it's very useful to sit down and understand why.

                        – Useless
                        Jan 10 at 17:12











                      • That's all true, but you are currently inferring that the asker did none of that, simply because they didn't revert that one change. They probably did realize that the two usings were equivalent in the process of getting the code to compile (because the change did not change the error message), at which point it's simpler to leave it there than to revert it - and why would you waste the effort if you have 3 other compiler messages left to worry about? I don't think the scolding (that's what it feels like to me as an unrelated third) is appropriate here.

                        – Max Langhof
                        Jan 10 at 17:18













                      • Possibly! I might be reading too much into the phrase what I figured out would work after some googling, but that's how it comes across to me. The question doesn't suggest any particular understanding of what the changes mean, at least. Anyway, it's not meant to scold, but to reinforce the habit of trying to understand.

                        – Useless
                        Jan 10 at 17:28





















                      • It's safe to assume that these were more than "random code permutations". In fact, I'd bet that one of the error messages (use of undeclared identifier 'cout') that was googled at some point led to an answer along the lines of "you forgot using std::cout". I find the last paragraph unnecessarily patronising, especially given how they already did manage to fix all these errors with no more than one incidental change.

                        – Max Langhof
                        Jan 10 at 17:01













                      • The problem if that if you're introducing incidental changes, that means you don't know which changes were important, which means you don't know why they worked or how to avoid the problem in future.

                        – Useless
                        Jan 10 at 17:10











                      • The key point isn't that you should never hack on something until it works - you can't either learn or sustain your motivation in a vacuum - but that you need to learn to read the error message, and when your code finally works, it's very useful to sit down and understand why.

                        – Useless
                        Jan 10 at 17:12











                      • That's all true, but you are currently inferring that the asker did none of that, simply because they didn't revert that one change. They probably did realize that the two usings were equivalent in the process of getting the code to compile (because the change did not change the error message), at which point it's simpler to leave it there than to revert it - and why would you waste the effort if you have 3 other compiler messages left to worry about? I don't think the scolding (that's what it feels like to me as an unrelated third) is appropriate here.

                        – Max Langhof
                        Jan 10 at 17:18













                      • Possibly! I might be reading too much into the phrase what I figured out would work after some googling, but that's how it comes across to me. The question doesn't suggest any particular understanding of what the changes mean, at least. Anyway, it's not meant to scold, but to reinforce the habit of trying to understand.

                        – Useless
                        Jan 10 at 17:28



















                      It's safe to assume that these were more than "random code permutations". In fact, I'd bet that one of the error messages (use of undeclared identifier 'cout') that was googled at some point led to an answer along the lines of "you forgot using std::cout". I find the last paragraph unnecessarily patronising, especially given how they already did manage to fix all these errors with no more than one incidental change.

                      – Max Langhof
                      Jan 10 at 17:01







                      It's safe to assume that these were more than "random code permutations". In fact, I'd bet that one of the error messages (use of undeclared identifier 'cout') that was googled at some point led to an answer along the lines of "you forgot using std::cout". I find the last paragraph unnecessarily patronising, especially given how they already did manage to fix all these errors with no more than one incidental change.

                      – Max Langhof
                      Jan 10 at 17:01















                      The problem if that if you're introducing incidental changes, that means you don't know which changes were important, which means you don't know why they worked or how to avoid the problem in future.

                      – Useless
                      Jan 10 at 17:10





                      The problem if that if you're introducing incidental changes, that means you don't know which changes were important, which means you don't know why they worked or how to avoid the problem in future.

                      – Useless
                      Jan 10 at 17:10













                      The key point isn't that you should never hack on something until it works - you can't either learn or sustain your motivation in a vacuum - but that you need to learn to read the error message, and when your code finally works, it's very useful to sit down and understand why.

                      – Useless
                      Jan 10 at 17:12





                      The key point isn't that you should never hack on something until it works - you can't either learn or sustain your motivation in a vacuum - but that you need to learn to read the error message, and when your code finally works, it's very useful to sit down and understand why.

                      – Useless
                      Jan 10 at 17:12













                      That's all true, but you are currently inferring that the asker did none of that, simply because they didn't revert that one change. They probably did realize that the two usings were equivalent in the process of getting the code to compile (because the change did not change the error message), at which point it's simpler to leave it there than to revert it - and why would you waste the effort if you have 3 other compiler messages left to worry about? I don't think the scolding (that's what it feels like to me as an unrelated third) is appropriate here.

                      – Max Langhof
                      Jan 10 at 17:18







                      That's all true, but you are currently inferring that the asker did none of that, simply because they didn't revert that one change. They probably did realize that the two usings were equivalent in the process of getting the code to compile (because the change did not change the error message), at which point it's simpler to leave it there than to revert it - and why would you waste the effort if you have 3 other compiler messages left to worry about? I don't think the scolding (that's what it feels like to me as an unrelated third) is appropriate here.

                      – Max Langhof
                      Jan 10 at 17:18















                      Possibly! I might be reading too much into the phrase what I figured out would work after some googling, but that's how it comes across to me. The question doesn't suggest any particular understanding of what the changes mean, at least. Anyway, it's not meant to scold, but to reinforce the habit of trying to understand.

                      – Useless
                      Jan 10 at 17:28







                      Possibly! I might be reading too much into the phrase what I figured out would work after some googling, but that's how it comes across to me. The question doesn't suggest any particular understanding of what the changes mean, at least. Anyway, it's not meant to scold, but to reinforce the habit of trying to understand.

                      – Useless
                      Jan 10 at 17:28




















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54131940%2fim-doing-a-course-but-the-things-the-lecturer-says-works-dont%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                      Mangá

                       ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕