What is Ostream Operator?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <ostream>
#include <unistd.h>
using namespace std;
long double firstVariable(0);
long double secondVariable(0);
long double total(0);
wchar_t op();
int totalApplier();
void titleScreenPause()
int titleScreen(0);
int main()
{
cout << "Welcome to Calculator_For_Linux" << endl;
void titleScreenPause();
cout << "1: Start 2: Themes 3: About 4: Exit" << endl;
cin >> titleScreen;
if ( titleScreen == 1 )
{
cout << "Ok, enter the first variable (Ex. 1)" << endl;
cin >> firstVariable << endl;
cout << "Ok, now enter an operator (Ex. +)" << endl;
cin >> op << endl;
cout << "Ok, now enter a second and final variable. (Ex. 1)" << endl;
cin >> secondVariable << endl;
}
else if ( titleScreen == 4 );
{
}
return 0;
}
void totalApplier()
{
if( op == + )
{
total = firstVariable + secondVariable;
cout << total << endl;
}
else if( op == -)
{
total = firstVariable - secondVariable;
cout << total;
}
void titleScreenPause()
{
sleep(5);
}
|
I am using Ubuntu KDE Trusty, and my compiler is g++.
Whenever I try to compile the code above g++ outputs:
CFL.cpp:19:1: error: expected initializer before 'int'
int titleScreen(0);
^
CFL.cpp: In function 'int main()':
CFL.cpp:30:9: error: 'titleScreen' was not declared in this scope
cin >> titleScreen;
^
CFL.cpp:37:25: error: no match for 'operator<<' (operand types are 'std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}' and '<unresolved overloaded function type>')
cin >> firstVariable << endl;
^
CFL.cpp:37:25: note: candidates are:
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from CFL.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2753:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
That's the most I could fit.
I know it's a lot, but I want to learn C++ really bad and this is killing me.