USEFUL C++ TUTORIAL!!!

All tutorials created in C++ to be posted in here.
4 posts Page 1 of 1
Contributors
User avatar
wrighty1986
VIP - Donator
VIP - Donator
Posts: 119
Joined: Sat Sep 12, 2009 11:55 am

USEFUL C++ TUTORIAL!!!
wrighty1986
What we are going to code today is quite something. Basically, You will ask the user how many arrays you want create. And you will ask values that the user wants through his input(integer values only!(for now)). And we are going to take the values the user inputed and organize it and save it into a text file called "Datas.txt".

This can be very helpful for beginners. I hope you guys learn something from it.
Code: Select all
//Necessary knowledge... Dynamic Memory Allocation
//Really cool Program!. No joke!

//Declaring our Headers
#include <iostream> // input and output functions
#include <fstream> // input and output file functions
#include "windows.h" // Sleep Function

using namespace std;

int main()
{
    //Title Code for the program
    system("title Array Creator, Manager, and Storer");
    //Declaring necessary integers
    int i,n;
    /*This is a pointer because it is necessary to Allocate the Memory
    (I, myself don't completely know why)*/
    int * p;
    //Asking the how many arrays does the User Wants
    cout << "How many Arrays:";
    //Getting input
    cin >> i;
    /* P is pointing to the address of 'i' which is dynamically Allocated
    using the keyword 'new' it is int because We are only recieving integer values
    plus, you will get an error if you make it new 'char' */
    p = new int[i];

    //If user enters 0, there won't be 0 arrays! Duh!
    if(p == 0)
    {
        //Message
        cout << "Arrays Cannot be Created...";
    }

    /*This loop is going to run as many times as the value
    the user inputed*/
    for(int n=0; n<i; n++)
    {
        //Message
        cout << "Enter your Array[" << n << "]:";
        //Input
        cin >> p[n];
    }
        //My Favorite part. 
        /*ofstream is a data type inside <fstream.h> which stands for
        'output file stream'. We are going to name it dataP*/
        ofstream dataP;
        //dataP.open creates the file if not existing with the name
        dataP.open("Datas.txt");
        /*This is the easy part. To actually input something to the file
        you simply do like a cout statement. dataP << Message;*/
        dataP << "~Array-Datas~\n\n";
        /*This for loop is to enter the values we got from the previous for loop
        to the File*/
        for(int n=0; n<i; n++)
        {
            //Organizes very neatly!
            dataP << "Array[" << n << "]: " << p[n] << "\n";
        }
        dataP.close(); // this is important, This saves the data.
        //This is just so extra Junk to spice up the program to look official! Lame!
        system("CLS"); // clears Screen
        cout << "Sending Datas from Arrays to Datas.txt" << endl; // Message
        Sleep(1500); // Sleep. The value is in Milliseconds. which means 1500 is 1.5 seconds
        cout << "Check the Program Directory for datas"; // Message
        cout << endl;
        system("PAUSE>NUL"); 
        return 0;
} 
Back Aegean sorry not been on i.v just been moving.
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1891
Joined: Wed Dec 16, 2009 9:56 pm

Re: USEFUL C++ TUTORIAL!!!
zachman61
wow i like C++ but never new anything lol ii like it
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
wrighty1986
VIP - Donator
VIP - Donator
Posts: 119
Joined: Sat Sep 12, 2009 11:55 am

Re: USEFUL C++ TUTORIAL!!!
wrighty1986
lol c++ is harder then vb i like vb better my self .
Back Aegean sorry not been on i.v just been moving.
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

Re: USEFUL C++ TUTORIAL!!!
mikethedj4
I agree C++ is very confusing to me, but I would so love to learn it along with C#, I know a little Java and Ruby. (I know Java more than any programming language)
4 posts Page 1 of 1
Return to “C++ Tutorials”