"using namespace std;" doesn't work in Visual Studio 2008 for outputting to file

I was trying to compile the following program I found on the Internet::

#include <fstream>#include <iostream>int main(){ using namespace std; // ofstream is used for writing files // We'll make a file called Sample.dat ofstream outf("Sample.dat"); // If we couldn't open the output file stream for writing if (!outf) { // Print an error and exit cerr << "Uh oh, Sample.dat could not be opened for writing!" << endl; exit(1); } // We'll write two lines into this file outf << "This is line 1" << endl; outf << "This is line 2" << endl; return 0; // When outf goes out of scope, the ofstream // destructor will close the file}

It wasn't till I completely removed "using namespace std;" and instead used "simpio.h" (one of the libraries provided with an online class I found) that I solved the problem.

How can I use these different functions without including "simpio.h". I want to learn to do it the same way everyone else does it in Visual Studio rather than using libraries that are only used in a single course.

#include <fstream>#include <iostream>using namespace std; // <-- place it hereint main(){ // ofstream is used for writing files // We'll make a file called Sample.dat ofstream outf("Sample.dat"); // If we couldn't open the output file stream for writing if (!outf) { // Print an error and exit cerr << "Uh oh, Sample.dat could not be opened for writing!" << endl; exit(1); } // We'll write two lines into this file outf << "This is line 1" << endl; outf << "This is line 2" << endl; return 0; // When outf goes out of scope, the ofstream // destructor will close the file}

#include <fstream>#include <iostream>int main(){ // ofstream is used for writing files // We'll make a file called Sample.dat std::ofstream outf("Sample.dat"); // If we couldn't open the output file stream for writing if (!outf) { // Print an error and exit std::cerr << "Uh oh, Sample.dat could not be opened for writing!" << std::endl; exit(1); } // We'll write two lines into this file outf << "This is line 1" << std::endl; outf << "This is line 2" << std::endl; return 0; // When outf goes out of scope, the ofstream // destructor will close the file}

and edit it's contents I still get an error. That class blank pc project only works when I omit "using namespace std;" and include "simpio.h" (which is a custom library for the class). However, the class blank project still compiles when I use your "cl.exe main.cc" with the "using namespace std;".

#include <fstream>#include <iostream>using namespace std; // <-- place it hereint main(){ // ofstream is used for writing files // We'll make a file called Sample.dat ofstream outf("Sample.dat"); // If we couldn't open the output file stream for writing if (!outf) { // Print an error and exit cerr << "Uh oh, Sample.dat could not be opened for writing!" << endl; exit(1); } // We'll write two lines into this file outf << "This is line 1" << endl; outf << "This is line 2" << endl; return 0; // When outf goes out of scope, the ofstream // destructor will close the file}

The following diagram presents a diamond class hierarchy:
As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…

In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…

The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.