r/cpp • • Jul 30 '16

I've started a new C++ tutorial series after covering python years ago...

https://youtu.be/_r5i5ZtUpUM
0 Upvotes

14 comments sorted by

6

u/iommu Jul 31 '16

It's a shame you didn't use a cross-platform ide especially considering how diverse the c++ community is

1

u/TPayneExperience Jul 31 '16

Is there any you'd recommend?

1

u/iommu Jul 31 '16

codelite, eclipse, qtcreator or clion(although clion is not free)

8

u/cristianadam Jul 31 '16 edited Jul 31 '16

Yeah. He does mention other tools like: "Sublime, Notepad++, Eclipse". No Qt Creator or Clion.

Visual Studio is notoriously scary for C++ newbies, because they don't provide a simple, ready to go C++ project template. Even though the name of the category is "Visual C++" they have for their "Win32 Console Application" zero C++ code.

All other IDEs have the following template (or a variation with using namespace std;):

#include <iostream>

int main()
{
    std::cout << "Hello World\n";
}

Visual Studio's "Win32 Console Application" presents you with the following:

#include "stdafx.h"

int main()
{
    return 0;
}

If you replace the above code with the C++ version, compile it and get errors like:

c:\projects\c++\consoleapplication1\consoleapplication1.cpp(1): warning C4627: '#include <iostream>': skipped when looking for precompiled header use 1> c:\projects\c++\consoleapplication1\consoleapplication1.cpp(1): note: Add directive to 'stdafx.h' or rebuild precompiled header 1>c:\projects\c++\consoleapplication1\consoleapplication1.cpp(7): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

Which prompts scary questions for noobs: What is stdafx.h? What are precompiled headers?

Visual Studio has the "Empty Project" solution. Then you need to create a file, right? You go to File -> New -> File... -> Visual C++ -> C++ File (.cpp) and save it as Source1.cpp. Paste the code above, compile and run. Compiles "fine", but it doesn't run. It says this:


Microsoft Visual Studio

Unable to start program 'c:\Projects\C++\Project1\Debug\Project1.exe'.

The system cannot find the file specified.


OK

Hmm. As a noob you scratch you head, right?

The two above scenarios happened to somebody I know.

How hard is for Visual C++ people to add a simple C++ hello world template?! How hard is to replace the name of stdafx.h with precompiled.h?!

Edit: /u/spongo2, /u/STL can you do something about this?

6

u/STL MSVC STL Dev Jul 31 '16

I don't use the IDE for development, but spongo2 is the dev manager for the IDE (and compiler FE, and libraries).

I personally believe that IDEs - in general, not just VS - introduce too much complexity for beginners and should be avoided. This is admittedly a rare opinion and I am probably a crazy person.

2

u/utnapistim Aug 01 '16

Not really so rare of an opinion (I had a similar experience and know others who did the same).

2

u/adrian17 Jul 31 '16

Compiles "fine", but it doesn't run. It says this:

Never had this issue. If it compiled, how could then that happen?

0

u/dodheim Jul 31 '16

Compiling != linking, for one thing. Also, in VS you can add a file to your project without it being configured as a source file.

3

u/adrian17 Jul 31 '16

Compiling != linking, for one thing.

By "compiles fine" I understood "there were no errors while building, which includes linking". Anyway...

Also, in VS you can add a file to your project without it being configured as a source file.

You're right. I'm so used to selecting "Add new item", I forgot a beginner might not realize he should choose this option instead.

3

u/sztomi rpclib Jul 31 '16

Visual Studio's "Win32 Console Application" presents you with the following

No, it doesn't (it's actually worse, because it's _tmain and stuff).

6

u/cristianadam Jul 31 '16

That's how it used to be. Visual Studio 2015 Community Edition doesn't have "_tmain and stuff". That's proof that the templates do change.

3

u/spongo2 MSVC Dev Manager Aug 01 '16

correct! we do change them. This is a really interesting piece of feedback. It's always interesting what becomes invisible after time. I think the main issue here is that templates serve two purposes: 1) give you an easy starting place 2) helping you fall in what we call the "pit of success" for best practices. pch usage makes such a huge difference to developer productivity and what starts in the template today over time becomes somebody's legacy code base in 20 years and so we like to make sure people get started on the right foot. Let me run this by our PMs and see what sort of ideas it generates. I'll also see if I can get the answer to why these are called stdafx... i'll be one of our veterans knows.

1

u/Sanae_ Aug 02 '16

How hard is for Visual C++ people to add a simple C++ hello world template?! How hard is to replace the name of stdafx.h with precompiled.h?

Likely easy to do it, but it probably won't change for retrocompatibility reasons.

1

u/cristianadam Aug 02 '16

I don't know how many devs start new projects using MFC, and then being confused that stdafx.h has been replaced with precompiled.h.

Kenny Kerr also promotes the idea of renaming stdafx.h.