answersLogoWhite

0


Best Answer

You are completely wrong here.

Another answer:

There is nothing to say you cannot use cin or coutoutside the main() function (for example, you can use them in a function called from main()). However, using them before main() has been called (e.g. in the constructor of a static object) can have disastrous consequences: cin and cout are themselves static objects, and static initialisation order is undefined. Thus you could be calling them before they have been properly constructed.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why Cin and Cout cannot be used outside the main function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write an application that displays in the command window a box an oval an arrow and a diamond using asterisks as follows?

the code for the box is: # include <iostream> using namespace std; void main () { cout << "*********\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*********\n"; the code for the oval is: # include <iostream> using namespace std; void main () { cout << " ***\n"; cout <<" * *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<" * *\n"; cout << " ***\n"; the code for the arrow is: # include <iostream> using namespace std; void main () { cout << " * \n"; cout <<" ***\n"; cout <<"*****\n"; cout <<" * \n"; cout <<" * \n"; cout <<" * \n"; cout <<" * \n"; cout <<" * \n"; the code for the diamond: # include <iostream> using namespace std; void main () { cout << " *\n "; cout <<" * *\n"; cout<<" * *\n"; cout<<" * *\n"; cout<<"* *\n"; cout<<" * *\n"; cout<<" * *\n"; cout <<" * *\n"; cout << " *\n "; }


How do youuse the 'long' function in turbo c?

#include #include void main() { long 11; clrscr(); cout<<"size of long="< getch(); }


Can you use the same function name for a member functoin of a class and an outside function in the same program file?

Yes you can use the same function name for a member function and an external function. They are primarily distinguished by the number and type of arguments they accept (the function signature). If they match exactly, then the scope resolution operator (::) is used to differentiate them by namespace. The class namespace is the class name itself. The external function uses global scope unless scoped to another namespace. When the scope is not explicitly stated, then the scope is implied by the call site. Note that whenever there is any ambiguity about which function is implied, the compiler will emit an error indicating where the ambiguity lies, and the program will ultimately fail to compile.


What is function Explain the user define function with example?

Function is a logically grouped piece of code allowing perform certain types of operations. Function can return value (int, double etc) or be void type - meaning they do not return value. Functions allow to make code cleaner by moving out chunks of code of main body. For instance you want to write a function that finds area of rectangular. #include <iostream> using std cin; using std cout; using std endl; using std get; int main() { double sideA = 0.0; cout << "Enter side a of rectagular: "; cin >> sideA; double sideB = 0.0; cout << endl << "Enter side b of rectangular: "; cin >> sideB; //This part passes sides a and b to user defined function "Square" cout << endl << "Area of rectangular is: " << Square(a, b); cin.get(); return 0; } //definition of user defined function Square double Square(double a, double b) { return (a * b); }


Explain you how you can impliment programme in c language without main function?

You can't. If you have no main function, then there is no entry point to your code and it cannot be executed. Code without a main function is essentially a library. In MS Windows, GUI mode, you don't have to have main function. (WinMain is used instead).

Related questions

What is scope of varaible?

In c++, variables exist in blocks of code and are destroyed after the block ends. Consider this example: <pre> #include <iostream> int main() { using namespace std; int x; cin << x; cout >> "you entered" >> x; return 0; } </pre> The variable x is declared in main, and is destroyed after main is finished. This means that x has <b>function scope</b>. It cannot be used outside main(). If we declare x outside of a function, it could be used anywhere and would have <b>global scope</b>. Learncpp.com has a good explanation of variable scope.


Write an application that displays in the command window a box an oval an arrow and a diamond using asterisks as follows?

the code for the box is: # include <iostream> using namespace std; void main () { cout << "*********\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*********\n"; the code for the oval is: # include <iostream> using namespace std; void main () { cout << " ***\n"; cout <<" * *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<" * *\n"; cout << " ***\n"; the code for the arrow is: # include <iostream> using namespace std; void main () { cout << " * \n"; cout <<" ***\n"; cout <<"*****\n"; cout <<" * \n"; cout <<" * \n"; cout <<" * \n"; cout <<" * \n"; cout <<" * \n"; the code for the diamond: # include <iostream> using namespace std; void main () { cout << " *\n "; cout <<" * *\n"; cout<<" * *\n"; cout<<" * *\n"; cout<<"* *\n"; cout<<" * *\n"; cout<<" * *\n"; cout <<" * *\n"; cout << " *\n "; }


How do youuse the 'long' function in turbo c?

#include #include void main() { long 11; clrscr(); cout<<"size of long="< getch(); }


How do you make a calculator using switch statement?

In C++: #include <iostream> using namespace std; int main() { int x, y; char func; cout << "Enter a number: "; cin >> x; cout << "Choose Function: "; cin >> func; cout << "Enter another number: "; cin >> y; switch(func) { case '+': cout << x + y << endl; break; case '-': cout << x - y << endl; break; case '*': cout << x * y << endl; break; case '/': cout << x / y << endl; break; default: cout << "Invalid Function!" << endl; break; } char wait; cin >> wait; return 0; }


Program to generate a pattern a aba abcba?

#include<iostream.h> void main() { cout<<' '<<' '<<"a"<<'\n'; cout<<' '<<"a"<<"b"<<"a"<<'\n'; cout<<'a'<<'b'<<'c'<<'b'<<'a'<<"\n"; }


How do you declare variable as global?

You declare it outside of any class or function. Example: #include <iostream> using namespace std; int globalint = 52; int main(){ cout<<globalint<<endl; globalint=73; cout<<globalint<<endl; return(0) } Or, If you like C code: #include <stdio.h> int globalint = 52; int main(){ printf ("GlobalInt: %d\n", globalint); globalint=73; printf ("GlobalInt: %d\n", globalint); exit(0); }


How do you do declare variables?

You declare it outside of any class or function. Example: #include <iostream> using namespace std; int globalint = 52; int main(){ cout<<globalint<<endl; globalint=73; cout<<globalint<<endl; return(0) } Or, If you like C code: #include <stdio.h> int globalint = 52; int main(){ printf ("GlobalInt: %d\n", globalint); globalint=73; printf ("GlobalInt: %d\n", globalint); exit(0); }


Can you use the same function name for a member functoin of a class and an outside function in the same program file?

Yes you can use the same function name for a member function and an external function. They are primarily distinguished by the number and type of arguments they accept (the function signature). If they match exactly, then the scope resolution operator (::) is used to differentiate them by namespace. The class namespace is the class name itself. The external function uses global scope unless scoped to another namespace. When the scope is not explicitly stated, then the scope is implied by the call site. Note that whenever there is any ambiguity about which function is implied, the compiler will emit an error indicating where the ambiguity lies, and the program will ultimately fail to compile.


What is function Explain the user define function with example?

Function is a logically grouped piece of code allowing perform certain types of operations. Function can return value (int, double etc) or be void type - meaning they do not return value. Functions allow to make code cleaner by moving out chunks of code of main body. For instance you want to write a function that finds area of rectangular. #include <iostream> using std cin; using std cout; using std endl; using std get; int main() { double sideA = 0.0; cout << "Enter side a of rectagular: "; cin >> sideA; double sideB = 0.0; cout << endl << "Enter side b of rectangular: "; cin >> sideB; //This part passes sides a and b to user defined function "Square" cout << endl << "Area of rectangular is: " << Square(a, b); cin.get(); return 0; } //definition of user defined function Square double Square(double a, double b) { return (a * b); }


Explain you how you can impliment programme in c language without main function?

You can't. If you have no main function, then there is no entry point to your code and it cannot be executed. Code without a main function is essentially a library. In MS Windows, GUI mode, you don't have to have main function. (WinMain is used instead).


Write a function that print a triangle of stars?

Function to print star triangle in c++#include#includevoid starfunction(int); //You can give any function namevoid main(){int a;clrscr();couta;star(a);getch();}void starfunction(int r ){for(int i=1;i


Function in C plus plus that takes in any number parameter and returns the string representation of it?

#include#includeusing std::cin;using std::cout;using std::endl;using std::string;int main(){string number = "0";cout number;cout