You are viewing our Forum Archives. To view or take place in current topics click here.
C++ Tutorial Beginner
Posted:

C++ Tutorial BeginnerPosted:

IIII
  • Video King
Status: Offline
Joined: Aug 19, 201211Year Member
Posts: 774
Reputation Power: 25
Status: Offline
Joined: Aug 19, 201211Year Member
Posts: 774
Reputation Power: 25
Hello World

#include <iostream>

using namespace std;

int main()
{
cout<<"Hello World";
system("pause");
}


Input Output Strings

#include <iostream>
using namespace std;
int main()
{
//Creates The String userinput
string userinput;
//Prints To Screen
cout<<"Enter Your Name: ";
//Takes What User Typed in and puts it in userinput string
cin>>userinput;
//Prints Userinput String To Screen
cout<<userinput;
system("PAUSE");
}


Example usage of Define

#include <iostream>
#define pausethish0e system("pause");
#define showmetext cout
using namespace std;
int main()
{
showmetext<<"This Shows u What you can do with a define" << endl;
pausethish0e
}


Looping with Labels

#include <iostream>
#define pausethish0e system("pause");
using namespace std;
int main()
{
thisisalabel:
cout<<"Example oF Looping with a label" << endl;
pausethish0e
goto thisisalabel;
}


Looping with do while

#include <iostream>
#define pausethish0e system("pause");
using namespace std;
int main()
{
do{
cout<<"Example oF Looping with a while true" << endl;
pausethish0e
}while(true);
}


Breaking a Do while Loop

#include <iostream>
using namespace std;
int main()
{
do{
string ans;
cout<<"Example oF Looping with a while true with a break Enter '1' to Break the loop" << endl;
cin>>ans;
if(ans=="1")
break;
}while(true);
}


Simple Counting

#include <iostream>
using namespace std;
int main()
{
for(int counter=0; counter<=10; counter++)
{
cout<<counter<<endl;
}
system("pause");

}
#2. Posted:
Tolerated
  • TTG Addict
Status: Offline
Joined: Oct 10, 201112Year Member
Posts: 2,175
Reputation Power: 94
Status: Offline
Joined: Oct 10, 201112Year Member
Posts: 2,175
Reputation Power: 94
Not a good way to teach people c++, a beginner would not understand a lot of your code examples and just using titles does not help, each part of the code must be commented so that beginners would know what each lines means and what it does.
#3. Posted:
SovietGnome
  • TTG Addict
Status: Offline
Joined: Dec 02, 201013Year Member
Posts: 2,244
Reputation Power: 89
Status: Offline
Joined: Dec 02, 201013Year Member
Posts: 2,244
Reputation Power: 89
I wouldn't use
system("pause");

at the end of the program as it is a VERY bad habit to get into. So if people learn off this, they might pick that up. Remember system() is EVIL

If you return 0 at the end of main, your compiler should know to keep the terminal up. Unless your compiler isn't very clever. So you could do that instead of using system(). There is always an alternative to using system. I am not saying don't use it, but it can be a bad thing to get into. / get people into.

Also, I am sure you need to include the <windows.h> / <cstdlib> header if you are going to use system() function anyways...
#4. Posted:
xplodingtaco1
  • Prospect
Status: Offline
Joined: Mar 05, 201113Year Member
Posts: 668
Reputation Power: 26
Status: Offline
Joined: Mar 05, 201113Year Member
Posts: 668
Reputation Power: 26
Not really much of a tutorial. More of a copy and paste fest. Maybe a voice explanation? Or some more in-depth comments in the code?
#5. Posted:
Evigishki
  • TTG Senior
Status: Offline
Joined: Aug 24, 201013Year Member
Posts: 1,624
Reputation Power: 83
Status: Offline
Joined: Aug 24, 201013Year Member
Posts: 1,624
Reputation Power: 83
xplodingtaco1 wrote Not really much of a tutorial. More of a copy and paste fest. Maybe a voice explanation? Or some more in-depth comments in the code?


Completely agree with you, this topic really seems like a copy and paste thing. Don't get me wrong OP, it's in no means a bad topic, but comments and additional information would really benefit beginners to figure out C++
#6. Posted:
IIII
  • Rising Star
Status: Offline
Joined: Aug 19, 201211Year Member
Posts: 774
Reputation Power: 25
Status: Offline
Joined: Aug 19, 201211Year Member
Posts: 774
Reputation Power: 25
xplodingtaco1 wrote Not really much of a tutorial. More of a copy and paste fest. Maybe a voice explanation? Or some more in-depth comments in the code?


Get me the link i copy and pasted from, let me know when you find it
#7. Posted:
xplodingtaco1
  • Prospect
Status: Offline
Joined: Mar 05, 201113Year Member
Posts: 668
Reputation Power: 26
Status: Offline
Joined: Mar 05, 201113Year Member
Posts: 668
Reputation Power: 26
8th wrote
xplodingtaco1 wrote Not really much of a tutorial. More of a copy and paste fest. Maybe a voice explanation? Or some more in-depth comments in the code?


Get me the link i copy and pasted from, let me know when you find it

No i am not saying you copy and pasted it, I am saying that all people that are trying to learn from this is copy and paste the code. Sorry for the misunderstanding.
#8. Posted:
Gary
  • Retired Staff
Status: Offline
Joined: Mar 09, 201212Year Member
Posts: 5,781
Reputation Power: 5267
Motto: Consume Tacobell. Play RuneScape.
Motto: Consume Tacobell. Play RuneScape.
Status: Offline
Joined: Mar 09, 201212Year Member
Posts: 5,781
Reputation Power: 5267
Motto: Consume Tacobell. Play RuneScape.
Word to the wise older compilers use
#include <iostream.h>

instead of just plain old
#include <iostream>
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.