problems with include files in Dev-Cpp 4.9.8.0

This is a discussion on problems with include files in Dev-Cpp 4.9.8.0 within the C++ Programming forums, part of the General Programming Boards category; I jsut got Dev-Cpp 4.9.8.0 and i cant figure out what includes to put in the ones i were using ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    16

    problems with include files in Dev-Cpp 4.9.8.0

    I jsut got Dev-Cpp 4.9.8.0 and i cant figure out what includes to put in the ones i were using in 4.9.4.1 dont work... I need teh include for cout and cin for ifstream and ofstream and any other basic necesities for most programs



    EDIT: Does it have to do with my hard drive letter being F: not C:
    Last edited by mill1k; 04-03-2004 at 06:07 PM.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    What happens if you compile this:
    Code:
     #include <iostream>
     
     int main()
     {
       std::cout <<"hello world" <<std::endl;
     }
    [edit]
    >>Does it have to do with my hard drive letter being F: not C:
    Maybe, I expect you'll have to tell the compiler where your include libraries are located if they're not in the default location.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,269
    Goto
    Tools -> Compiler Options -> Directories
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    Quote Originally Posted by Hammer
    What happens if you compile this:
    Code:
     #include <iostream>
     
     int main()
     {
       std::cout <<"hello world" <<std::endl;
     }
    [edit]
    >>Does it have to do with my hard drive letter being F: not C:
    Maybe, I expect you'll have to tell the compiler where your include libraries are located if they're not in the default location.
    That complied fine...whats with the std::cout instead of just cout
    The complie seem to be looking in the right directories.
    But when i try adding #include <iostream> i get this error: 'cout' undeclared (first use function)
    EDIT: Ah i think that there was something wrong in the incude files seems to work fine now
    Last edited by mill1k; 04-04-2004 at 10:44 AM.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,269
    Dev-C++ uses the MinGW port of GCC, which tries the follow the current standards.

    These standards have something called namespaces.
    cout, cin, endl are examples of identifiers that belong to the std namespace.
    You then must use them as std::cout, std::cin, std::endl
    You could also declare at the start:
    using std::cout;
    using std::cin;
    using std::endl;
    and then use them as cout, cin, endl

    Conversely, you could use the entire namespace:
    using namespace std;
    but that generally defeats the purpose of namespaces, i.e. to avoid conflicts where identifiers have identical names in different libraries/modules/classes used in a program.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    I have a new problem is it possible to put
    Code:
    ofstream fouts2("Saves/save2.txt");
    in a Switch statement

  7. #7
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Yes.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  8. #8
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    Well i keep geting this error:
    Jump to case labels
    and
    crosses initialization of `std:fstream fouts1'

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,269
    what code did you use?

    You may have to place the code within a code block, e.g.
    Code:
    switch (something) {
    case 1:
    	{
    		//some code
    		ofstream fouts2("Saves/save2.txt");
    		//some code
    	}
    	break;
    default:
    	//some code
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    more like this:
    Code:
    case 2:
           ofstream fouts2("Saves/save2.txt");
           cout<<"\nEnter save name(Less then 10 charcters):";
           cin>>save2;
           fouts2<<save2<<"\n";
           fouts2<<turn<<"\n";
           fouts2<<money<<"\n";
           fouts2<<numfish<<"\n";
           fouts2.close();
           Menu();
           break;

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,269
    The corrected code should be:
    Code:
    case 2:
    	{
    		ofstream fouts2("Saves/save2.txt");
    		cout<<"\nEnter save name(Less then 10 charcters):";
    		cin>>save2;
    		fouts2<<save2<<"\n";
    		fouts2<<turn<<"\n";
    		fouts2<<money<<"\n";
    		fouts2<<numfish<<"\n";
    		fouts2.close();
    		Menu();
    	}
    	break;
    I'm not too sure why, but from my experience declaring variables within a case block always seems to have problems unless that block is explicitly placed in a code block by using braces.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  2. Global Variables, include files and classes
    By sharpstones in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2005, 11:06 AM
  3. Include files
    By disruptivetech in forum C++ Programming
    Replies: 7
    Last Post: 07-12-2005, 10:52 AM
  4. Problems with include
    By Iamien in forum C++ Programming
    Replies: 5
    Last Post: 06-07-2005, 02:49 PM
  5. Resources with Dev C++ Problem (many simple problems)
    By Zeusbwr in forum Windows Programming
    Replies: 4
    Last Post: 04-07-2005, 12:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21