CS253

CS253: Software Development with C++

Spring 2017

Implicit Inclusion

See this page as a slide show

Implicit Inclusion

CS253 Implicit Inclusion

Dubious Code

Is this code correct?

#include <iostream>

using namespace std;

int main() {
    string s = "hello\n";
    cout << s;
    return 0;
}
hello

Bad Code

#include <iostream>

using namespace std;

int main() {
    string s = "hello\n";
    cout << s;
    return 0;
}
hello

The code is not correct. A std::string was declared, but there is no #include <string>. But, still, it compiled. ☹

operator<<

Light Dawns

#include <iostream>

using namespace std;

int main() {
    string s = "hello\n";
    cout << s;
    return 0;
}
hello

Solution

#include <iostream>
#include <string>

using namespace std;

int main() {
    string s = "hello\n";
    cout << s;
    return 0;
}
hello

Theoretical

Is this just theoretical handwaving?

No. For nearly every assignment, somebody turns in code that compiles on their computer, but fails on CSU computers.

Modified: 2017-04-28T13:06

User: Guest

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building