I am programming using Visual studio C++, doing some win32 console application simple programs.
I am upgrading to visual studio 2008, and I cannot compile programs in C++ done with previous versions (6.0) because I always get a compiler error. For instance, if I write:

ifstream f("file.txt")

then the compiler tells me: "ifstream: undeclared identifier", although I have included fstream header file.

I am also having problems with two classes that I defined as "friends", but the compiler does not let me reference private members of one another...
Could someone tell me what to do?
Thank you.

You are using namespace std?

> I cannot compile programs in C++ done with previous versions (6.0)
Visual C++ 6.0 allows both old style and new style iostream code. Your program might be including fstream.h instead of fstream, and you have to tell the compiler what namespace the name is in:

#include <fstream> // Not <fstream.h>

int main()
  std::ifstream f("file.txt");


If your code uses the old headers, it's easier to just use using namespace std; than to prefix every standard name with std:: after changing the header to the new one:

#include <fstream>

using namespace std;

int main()
  ifstream f("file.txt");

  // Lots of other standard names used without std:: prefixes

Don't do that in new code though. using namespace std; should never be used at the global scope if you can avoid it.

You are using namespace std?

Thank you so much!! I have just now realized that I have to explicitly stating "using namespace std". This is different from the older version I have been using!

Problem solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.