CS253: Software Development with C++

Spring 2018

Using Namespace Std

See this page as a slide show

CS253 Using Namespace Std

Namespaces

#include <iostream>

using namespace std;

int main() {
    cout << 1/8.1;
    return 0;
}
0.123457

Namespaces

#include <iostream>

int main() {
    cout << 1/8.1;
    return 0;
}
c.cc: In function 'int main()':
c.cc:4:5: error: 'cout' was not declared in this scope
c.cc:4:5: note: suggested alternative:
In file included from c.cc:1:0:
/usr/local/gcc-6.3.0/include/c++/6.3.0/iostream:61:18: note:   'std::cout'

Namespaces

#include <iostream>

int main() {
    std::cout << 1/8.1;
    return 0;
}
0.123457

How it works

#include <iostream>

constexpr auto pi = 3.14159;
void cout() {
    std::cout << "π=" << ::pi << std::endl;
}

int main() {
    ::cout();
    return 0;
}
π=3.14159

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2018-04-24T16:57

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building