Swordrock's Blog

Just another WordPress.com site

C++ 3


READING INPUT

Iostream class allows user to enter input values .

“cin” which means console input let us give an input to the program

It is used with cin >>

Eg:

———————————————————

// C02 Eg 4

//converts decimal to octal and hex

#include <iostream>

using namespace std ;

int main ()

{

int number;

cout <<“enter a decimal number=”;   // we want user to enter a value

cin >>number ;  // we take value by console

cout <<“value in octal = 0”   // we print the value by cout object in octal form

<<oct<<number<<endl ;

cout <<“value in hex=0x”   // we print the valueby cout object in hexademical form

<<hex<<number<<endl ;

system (“pause”);   // we tell to program that wait until we push any key

}

—————————————————————-

Calling Other Programs

While writting codes , any program can be called by using Standart C function system () , that is declared in <cstdlib>

E.g :

————————————————————–

//C02

//calling other programs eg.5

#include <cstdlib>  //  we declare system ()

using namesapce std ;

int main ()

{

system (“Hello”);

system (“pause”);

}

————————————————————–


Introduction to strings

To use string , we must include “string.h” file to the program ,

String class is in the namespace of std so we will also add a using directive .

Eg :

————————————————————————–

// C02 hellostrings

//introdcution to strings eg

#include <string>

#include <iostream>

#include <cstdlib>

using namespace std ;

int main ()

{

string s1,s2 ; // we name two empty strings

string s3 = “Hello,world.”;  // s3 is initialized

string s4 (“i am “);  // another type of initilalizing

s2 = ” Today”;   // assigning to string

s1 = s3+” ” +s4 ;   //  you can combine strings like that

s1 +=”8″ ;  //  append to string is by using += operator

cout <<s1 + s2 + “!” << endl ;

system (“pause”);

}

These program will also work like that  :

————————————————————

Thanks for reading, that’s all for today .

Reklamlar

Kasım 2, 2010 - Posted by | C/C++ programming

Henüz yorum yapılmamış.

Bir Cevap Yazın

Aşağıya bilgilerinizi girin veya oturum açmak için bir simgeye tıklayın:

WordPress.com Logosu

WordPress.com hesabınızı kullanarak yorum yapıyorsunuz. Çıkış  Yap / Değiştir )

Twitter resmi

Twitter hesabınızı kullanarak yorum yapıyorsunuz. Çıkış  Yap / Değiştir )

Facebook fotoğrafı

Facebook hesabınızı kullanarak yorum yapıyorsunuz. Çıkış  Yap / Değiştir )

Google+ fotoğrafı

Google+ hesabınızı kullanarak yorum yapıyorsunuz. Çıkış  Yap / Değiştir )

Connecting to %s

%d blogcu bunu beğendi: