when doing oop in c++ will i still have to declare the usuall stuff at the top? like iostream and stdafx? and will i need to add the line: using namespace std;?
OOP is just a concept of programming, not a different version itself.
stdafx is VS exclusive header file, so it is not needed in any case. iostream probably, as it is the simplest way of input and output you may be using.
usingnamespace std;
Not necessarily. You can add std:: before anything that is in std namespace like std::cout;
Yes, you will need a main(). (Or a WinMain, if you write WIN32 GUI code.)
main could just be an empty function, if you have a global application object whose constructor starts the program running. But there are issues with using globals, and even if the application object is global, I would wait until main is called to activate it. That way you know for sure that the runtime library has finished its initialization.
Note that using can also be used at function scope, so you don't have to expose the whole of the std namespace to your whole program. This is useful if only a few functions do most of the processing that uses a lot of standard containers, algorithsm, ...
#include <iostream>
#include <string>
#include <vector>
// etc
// but no using namespace std;
void Test1()
{
usingnamespace std;
// do lots of stuff using strings, vectors, etc which would
// use a lot of std::s
}
int main()
{
std::cout << "Test 1" << std::endl;
Test1();
std::cout << std::endl;
return 0;
}
Note that you have been using classes the whole time more and likely, i.e istream, ostream, string, etc.. These are all just classes (or data types). Now, you are just going to make your own... and don't forget the golden rule: EVERY C++ program MUST have the function main.