Sunday, September 16, 2012

some basic for c++ beginers..

If you are a beginner for c++ ,just walk through it  ....
1. // this double slash not include in the program,and they used to make a simple -line comment within the program(/*.......*/  is used  for multiple line.
2.<iostream.h>- input output stream header file
Provides functionality to use an abstraction called streams specially designed to perform input and output operations on sequences of character, like files or strings.
Objects cin, cout are from iostream header.
<conio.h> console input output header file
conio.h is a C header file used in old MS-DOS compilers to create text user interfaces

Both are header files which contains libery of serveral functions (use for input & output ).
eg. clrscr() ,getch() are from conio.h.
<< extraction operator used to output something.
>>insertion operator used to read something.
This is type of opening files before we use these function.
If we use these function them without importing header files , sometimes compiler throws error.
 now look the example
//program for printing the sentence "Hellow world"one time

#include<iostream.h>
#include<conio.h>
void main()
{
cout<<"Hellow world";
getch();
}


check out a simple program which display 10 times the same sentence..

 #include<iostream.h>
#include<conio.h>
void main()
{
int i=0,n=10; // here we declare the values at the time of initialisation
while(i<n)  // if condition fails,the the loop will not execute
{
cout<<"Hellow world\n"; // \n is used to jump to next stence
i++; // incrementing the value of the i by one.
}
getch();
}

diisplays the  sentence hellow world  using for loop

#include<iostream.h>
#include<conio.h>
void main()
{
int i=0,n;
clrscr();   // this is a function used to clear the screen
cout<<"Enter the limit\n";
cin>>n;// reading the value at run time
for(i=0;i<n;i++)
{
cout<<"Hellow world\n";
}
getch();
}



No comments:

Post a Comment