Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C++ Programming Code Examples

C++ > Code Snippets Code Examples

Cout: uppercase, show base, hex

/* Cout: uppercase, show base, hex */ #include <iostream> using namespace std; int main() { cout.unsetf(ios::dec); cout.setf(ios::uppercase | ios::showbase | ios::hex); cout << 88 << '\n'; cout.unsetf(ios::uppercase); cout << 88 << '\n'; return 0; }

Consider a situation, when we have two persons with the same name, jhon, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area, if they live in different area or their mother's or father's name, etc. Same situation can arise in your C++ applications. For example, you might be writing some code that has a function called xyz() and there is another library available which is also having same function xyz(). Now the compiler has no way of knowing which version of xyz() function you are referring to within your code.

Clear specific format flags. Clears the format flags selected in mask. Function unsets the formatting flags identified by flags. The parameterized manipulator resetiosflags behaves in a similar way as this member function. This function does not return any value.

A return statement ends the processing of the current function and returns control to the caller of the function. A value-returning function should include a return statement, containing an expression. If an expression is not given on a return statement in a function declared with a non-void return type, the compiler issues an error message. If the data type of the expression is different from the function return type, conversion of the return value takes place as if the value of the expression were assigned to an object with the same function return type.

#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program.

The cout is a predefined object of ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to display the output on a console. On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout. The "c" in cout refers to "character" and "out" means "output". Hence cout means "character output". The cout object is used along with the insertion operator << in order to display a stream of characters.

Set specific format flags. The function setf() sets the io stream format flags of the current stream to fmtfl. The optional mask argument specifies that only the flags that are in both fmtfl and mask should be set. The return value is the previous configuration of io stream format flags. Member type fmtflags is a bitmask type (see ios_base::fmtflags). Function returns the format flags selected in the stream before the call. The first form (1) sets the stream's format flags whose bits are set in fmtfl, leaving unchanged the rest, as if a call to flags(fmtfl|flags()).

A program shall contain a global function named main, which is the designated start of the program in hosted environment. main() function is the entry point of any C++ program. It is the point at which execution of program is started. When a C++ program is executed, the execution control goes directly to the main() function. Every C++ program have a main() function.



In the C++ Programming, The static keyword allows a variable to maintain its value among different function calls. If the value of a static variable changes when the variable has been






For example 6 is Perfect Number since divisor of 6 are 1, 2 and 3. Sum of its divisor is 1 + 2+ 3 =6 and 28 is also a 'Perfect Number' since 1+ 2 + 4 + 7 + 14= 28. Other 'Perfect Numbers': 496

In this C++ example, we have "two functions" one gets the values from user, assign them to structure members and returns the structure and the other function takes that structure as

In the program, the octal number is stored in the variable octalNumber, passed to function octalToDecimal(). This function converts the octal number passed by user to its equivalent