Thread: problems with include files in Dev-Cpp 4.9.8.0

  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
    28,413
    Goto
    Tools -> Compiler Options -> Directories
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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 09:44 AM.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 10:06 AM
  3. Include files
    By disruptivetech in forum C++ Programming
    Replies: 7
    Last Post: 07-12-2005, 09:52 AM
  4. Problems with include
    By Iamien in forum C++ Programming
    Replies: 5
    Last Post: 06-07-2005, 01:49 PM
  5. Resources with Dev C++ Problem (many simple problems)
    By Zeusbwr in forum Windows Programming
    Replies: 4
    Last Post: 04-06-2005, 11:08 PM