DevCpp Help

This is a discussion on DevCpp Help within the C++ Programming forums, part of the General Programming Boards category; I'm learning C++ at school on BC++. At home I use Dev C++ which is a little different from BC++. ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    7

    DevCpp Help

    I'm learning C++ at school on BC++. At home I use Dev C++ which is a little different from BC++. For example I have to add "using namespace std;" to use cout, cin etc.
    Code:
    #include <fstream>
    int main()
    {
        ifstream Fin("num.in");
        ofstream Fout("num.out");
        int n,x,i;
        i<=1;
        Fin>>n;
        while(i<=n)
        {
                   Fin>>x;
                   if(x>0) Fout<<x<<" ";
                   i=i+1;
                   }
                   Fin.close();
                   Fout.close();
                   return 0;
                   }
    This code works on BC++. It's suppose to get the positive numbers from those that we have. What do I have to add to make it work on Dev? I searched on Google, but I didn't find anythingthat could help me, and I don't really know what to search.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,439
    > For example I have to add "using namespace std;" to use cout, cin etc.
    Does your BC++ compiler not accept this or something? If it doesn't, then consider getting a better compiler which does.

    Besides, using namespace std; is poor style as you get EVERYTHING in the standard namespace, not just the things you need (it's a bit like using globals - sure it works, but it ain't pretty).
    Use things like
    std::cout << "hello world" << std::endl;


    > What do I have to add to make it work on Dev?
    Depends on what you mean.
    Does it compile?
    Does it run?
    Does it produce the same results?

    > i<=1;
    Erm, what's this supposed to do?
    Compare i (which is uninitialised) with 1, and throw the result of the comparison away.
    Try i = 1;
    if you want consistency.

    > At home I use Dev C++ which is a little different from BC++
    Being able to write code which works on any compiler should be the aim of every programmer.

    It's a lot harder to do that than just figuring out what your current compiler will let you get away with, but it will serve you well in the long run.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by Sessaru
    For example I have to add "using namespace std;" to use cout, cin etc.
    That would help here as well.
    All the standard library functions live in namespace std.
    Kurt

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    7
    I get the following errors:
    3: error: expected init-declarator before "using"
    3 error: expected `,' or `;' before "using"
    4: error: expected unqualified-id before '{' token
    4: error: expected `,' or `;' before '{' token

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    Where did you put your using statement?
    like this:
    Code:
    #include <fstream>
    using namespace std;
    int main()
    {
    	ifstream Fin("num.in");
    	ofstream Fout("num.out");
    	int n,x,i;
    	i=0;
    	Fin>>n;
    	while(i<n)
    	{
    		Fin>>x;
    		if(x>0) Fout<<x<<" ";
    		i=i+1;
    	}
    	Fin.close();
    	Fout.close();
    	return 0;
    }
    ?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    If you get the code to work, do what Salem suggested and stay away from using namespace std and prefix each object with the std:: qualifier.
    I'm just trying to be a better person - My Name Is Earl

  7. #7
    Registered User
    Join Date
    Dec 2006
    Posts
    12
    try converting 'Fin' with cin... try converting thw whole program into real c++ program...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DLL DevCPP won't take a min.....
    By lechat in forum C++ Programming
    Replies: 3
    Last Post: 11-24-2007, 02:38 PM
  2. DevCpp error: multiple definition of `img'
    By TriKri in forum C++ Programming
    Replies: 8
    Last Post: 01-01-2007, 07:11 PM
  3. [Linker error] undefined reference.(GTK, devcpp)
    By Firestarter in forum C Programming
    Replies: 2
    Last Post: 05-05-2006, 11:04 AM
  4. OpenGL and DevCPP: A dilemma for newbies
    By Sunny in forum Game Programming
    Replies: 12
    Last Post: 04-08-2005, 09:47 AM
  5. DevCPP
    By willkoh in forum C Programming
    Replies: 4
    Last Post: 02-05-2005, 08:21 AM

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