What's new

Closed Structure of a Program

Status
Not open for further replies.

DCCS

Forum Expert
Elite
Joined
Jun 10, 2013
Posts
7,175
Solutions
22
Reaction
17,644
Points
3,550
Hi guys eto po yung karugtong ng thread ni bro fazz12

Bago kayo mag proceed dito sa Thread na ito be sure na basahin niyo muna yung first part which is here Tutorial - Basic Programming using C++ ----- Introduction(Hello world) | PHCorner Community

Magdadagdag lang tayo ng statement sa program natin.
Yung unang ginawa natin ay "Hello World!". Ngayon naman dagdagan natin ng "I'm a C++ programmer"

Special Note: cout read as See-Out , std read as Studio

Okay let us start.

Part II

// my second program in C++
[HASHTAG]#include[/HASHTAG] <iostream>

int main ()
{
std::cout << "Hello World! ";
std::cout << "I'm a C++ program"; // Eto yung dinagdag natin.
}

Sa code natin ngayon nagdagdag tayo ng dalawang magkaibang statement. Kung Gusto niyong mag try i-run yung program pwede niyong gawin dito yan ---> You do not have permission to view the full content of this post. Log in or register now.

Katulad ng sinabi ko sa 1st page.
Pwede niyong paikliin ang statement like this

int main () { std::cout << " Hello World! "; std::cout << " I'm a C++ program "; }

Wag niyo lang kalilimutan ang head

[HASHTAG]#include[/HASHTAG] <iostream>

Complete code:

[HASHTAG]#include[/HASHTAG] <iostream>

int main () { std::cout << " Hello World! "; std::cout << " I'm a C++ program "; }

Pwede rin namang i-divide (hatiin sa dalawa o higit pa) ang code natin.
Like this:

int main ()
{
std::cout <<
"Hello World!"; // Prints Hello World!
std::cout
<< "I'm a C++ program"; // Prints I'm a C++ program
}

Part III: Using Namespace std

If you have seen C++ code before, you may have seen cout being used instead of std::cout. Both name the same object: the first one uses its unqualified name (cout), while the second qualifies it directly within the namespacestd(as std::cout).

cout is part of the standard library, and all the elements in the standard C++ library are declared within what is a called a namespace: the namespace std.

In order to refer to the elements in the std namespace a program shall either qualify each and every use of elements of the library (as we have done by prefixing cout with std::), or introduce visibility of its components. The most typical way to introduce visibility of these components is by means of using declarations:

Code:
using namespace std;

The above declaration allows all elements in the std namespace to be accessed in an unqualified manner (without the std:: prefix).

With this in mind, the last example can be rewritten to make unqualified uses of cout as:

Code:
// my second program in C++
#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World! ";
  cout << "I'm a C++ program";
}

Both ways of accessing the elements of the std namespace (explicit qualification and using declarations) are valid in C++ and produce the exact same behavior. For simplicity, and to improve readability, the examples in these tutorials will more often use this latter approach with using declarations, although note that explicit qualification is the only way to guarantee that name collisions never happen.
---------------
Dyan na lang muna sa ngayon :) try niyo i-run at isulat yung mga code ng walang tinginan para makabisado mo o niyo ang code (y)
 
Dear @DarkCore.CoreSec,

Since 2 years have passed since the last reply in this thread, I am locking it to prevent necroposting. Feel free to start a new thread or contact any forum staff if you want this to be reopened.

Thread closed.
 
Status
Not open for further replies.

Similar threads

Back
Top