CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: [RESOLVED] New

  1. #1
    Join Date
    Feb 2009
    Posts
    3

    [RESOLVED] New

    Im really new to this! but I'm typing this correctly down but I keep getting an error from it! Help me please..


    #include <iostream>
    int main()
    {

    int x= 5;
    int y= 7;
    std::cout << endl;
    std::cout << x + y << " " << x * y;
    std::cout << end;

    char response;
    std::cin >> response;
    return 0;
    }
    Last edited by Vaildinfection; March 10th, 2009 at 11:49 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: New

    What's end? Did you intend to write std::endl?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Feb 2009
    Posts
    3

    Re: New

    sorry Just fixed it! but I still error an with

    std::cout << endl;
    Last edited by Vaildinfection; March 10th, 2009 at 11:53 AM.

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: New

    Either refer to it as std::endl, or else put
    Code:
    using namespace std;
    at the top of your file under the include.

  5. #5
    Join Date
    Feb 2009
    Location
    Ukraine
    Posts
    64

    Re: New

    endl declared inside std namespace. So, you should write
    Code:
    using namespace std;
    
    int main()
    {
      ...
    }
    or point the namespace explicitly, as you do for cin and cout:
    Code:
    std::endl

  6. #6
    Join Date
    Feb 2009
    Location
    Ukraine
    Posts
    64

    Re: New

    Discovered the above message after posting my one and page refresh.

  7. #7
    Join Date
    Feb 2009
    Posts
    3

    Re: New

    #include <iostream>
    using namespace std;
    int main()
    {
    int x = 5;
    int y = 7;
    std::endl;
    std::cout << x + y << " " << x * y;
    std::end;
    char response;
    std::cin >> reponse;
    return 0;
    }


    I hope that's correct. I'm still getting the error. I'm sorry ><.. I feel stupid lol..
    Last edited by Vaildinfection; March 10th, 2009 at 12:14 PM.

  8. #8
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Lightbulb Re: New

    Quote Originally Posted by Vaildinfection View Post
    #include <iostream>
    using namespace std;
    int main()
    {
    int x = 5;
    int y = 7;
    std::endl;
    std::cout << x + y << " " << x * y;
    std::end;
    char response;
    std::cin >> reponse;
    return 0;
    }


    I hope that's correct. I'm still getting the error. I'm sorry ><.. I feel stupid lol..
    No it isn't correct. Have you been reading the replies at all? By the way, don't bother with "using namespace std" if you are going to qualify the names with "std::" anyway. That is just going to cause you trouble eventually and it is not a good idea to have this using declaration at the top of the file like that. The std::endl has to be inserted into the stream not written on a completely separate line as a completely separate statement. Please mark this thread resolved when you have figured it out.

  9. #9
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: New

    Quote Originally Posted by Vaildinfection
    I hope that's correct. I'm still getting the error.
    Well, if you are getting an error, it surely is not correct

    The problem is that you are still not spelling std::endl correctly in one place.

    By the way, please post your code in [code][/code] bbcode tags.

    EDIT:
    Oh yes, kempofighter's point is good too. As for the other point, note that using namespace std is a using directive, not a using declaration.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  10. #10
    Join Date
    Apr 2004
    Posts
    102

    Re: New

    Quote Originally Posted by Vaildinfection View Post
    #include <iostream>
    using namespace std;
    int main()
    {
    int x = 5;
    int y = 7;
    std::endl;
    std::cout << x + y << " " << x * y;
    std::end;
    char response;
    std::cin >> reponse;
    return 0;
    }


    I hope that's correct. I'm still getting the error. I'm sorry ><.. I feel stupid lol..
    You were closer your first effort. Also, in both your efforts, you missed the l in your second endl.

    Either,
    Code:
    #include <iostream>
    
    int main()
    {
    	int x= 5;
    	int y= 7;
    	std::cout << std::endl;
    	std::cout << x + y << " " << x * y;
    	std::cout << std::endl;
    
    	char response;
    	std::cin >> response;
    	return 0;
    }
    or
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    	int x= 5;
    	int y= 7;
    	cout << endl;
    	cout << x + y << " " << x * y;
    	cout << endl;
    
    	char response;
    	cin >> response;
    	return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured