HELP! i'm getting what seems like an erroneous error! i've got #include <string> in the top of my .cpp, but i keep getting the error 'string' does not name a type when i try to compile! why?!? any ideas? i thought #include <string> was what INCLUDED the library for using strings?? this is in a header file attached to a .cpp that i'm using to store classes and class member functions to be used by the client program, does that make a difference? i'll throw up the part of my code where it says i have this problem..:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <math.h>
#include <windows.h>
#include <string>
#include <cstdlib>
//using namespace std;
//********************************************************************
//CLASSES
//********************************************************************
//********************************************************************
//Class InvBin
//********************************************************************
class InvBin
{
private:
string description; // item name
int qty; // Quantity of items
// in this bin
and the error says:
'string' does not name a type
please excuse the LIST of includes... my prof told me that if you don't use it the compiler ignores it so it's not a bad idea to just make a master list, so you don't have to keep remembering to type in the ones you need...
oh! you're right on line 12.. and if i uncomment it, i shouldn't have any problems there right? also, i noticed in other student's examples that they didn't need to use the "namespace std;"
line in a header file, only in the main.cpp... but i didn't notice SPECIFICALLY if they were using the std:: class scope every time... does having the namespace line in everything complicate things at all? or is it more about efficiency in coding when it comes to wether or not you inlcude it?
Namespaces were meant to prevent cases where you give something the same name as something in one of those headers. When you write using namespace std you plop all of the stuff in the std namespace into the global namespace so you don't have to type std:: before everything. It comes at a price: you may accidentally give something the same name as something in the std namespace and cover it up or make it ambiguous as to which you want.
Your fellow students who put std:: before everything have the right idea.
If it is really a hassle you can do things like this:
1 2 3
using std::cout;
//...
cout << "stuff" << std::endl;
ok so when using it i need to avoid using anything in the standard namespace, like pre-defined common functions etc. (toupper, aoti, etc. ) and i'm predefined classes like the c++ string class.. am i right?
wow right on the front page... sadly that explains why i didn't see it... i've been using the search function for individuals references and never saw this page... well now i feel extra stupid :P but i also learned something, so i take solace in the fact that i may be stupid, but i'm getting smarter by the day :D THANKS A LOT!!!!!!!!