Unix/Linux C++ and Visual C++ differences

Hello, I am new the forum and I'm learning C++. I have programmed in C# for about a year. I am taking a C++ class where we are programming on Linux.

I don't want to waste any of your time so I'll make this short. Could someone point me in the direction where I can learn about the different C++ syntax’s and how the convert between the two?

The reason is on unix a sample C++ program looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

using namespace std;

int main()
{

  int myInt = 5;
  cout << myInt << endl;
  
  return 0;
}


However, when I fire up Microsoft Visual C++ (.Net 2008) - It looks like this:

1
2
3
4
5
6
#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
	return 0;	
}


If I try to use a "cout" statement it doesn't recognize cout, even though the stdafx.h header class contains a reference to stdio.h

So if anyone has any kind words about where to start understanding this I would appreciate it!

Thanks
I think stdio.h is old, you have to include iostream as in the first samples

EDIT: I suggest you not to mix .Net with standard
Last edited on
There's no such thing as "Linux C++" or "Visual C++" (in relation to the language. There is something called Visual C++, but it's not a dialect of C++). There's only standard-compliant C++, and everything else. Everything else includes all stupid, non-standard extensions proprietary compilers tend to have, such as having a main() by a different name, having main take exotic parameters, having main return anything other than int, non-standard methods in standard classes (you'll pay dearly for ever making me think there was an std::stack<T>::_Get_container(), Microsoft), etc.

With a little careful project creation, you can compile the first sample in VC++.
Yeah...it's because you are using .Net....Just copy/paste the Linux code into VC++ and it should work fine. (Well, at least it does on mine...I don't remember if I had to change anything)
If I try to use a "cout" statement it doesn't recognize cout


In response to this, from the first example you had:

using namespace std;

You want to have that in the second example in order for c++ to recognize cout and cin, at least without specific std::cout statements.
In order to have a standard C++ application I allways start from an Empty project (Not CLR) when working with VC++
Topic archived. No new replies allowed.