Thread: Help me with this weird error please

  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77

    Help me with this weird error please

    Code:
    #include "Security.h"
    
    
    #include <iostream>
    #include <SFML/Graphics.hpp>
    #include <SFML/Window.hpp>
    
    
    
    
    Security::Security()
    {
        //ctor
    }
    
    
    Security::~Security()
    {
        //dtor
    }
    
    
    void Security::ErrorMsg()
    {
        sf::RenderWindow ErrorBox(sf::VideoMode(200,100,32),"Error");
    
    
        sf::Text ErrorText;
        sf::Font ErrorFont;
    
    
        if(ErrorFont.loadFromFile("monospa1.ttf"))
            ErrorText.setFont(ErrorFont);
        ErrorText.setString("Access denied");
        ErrorText.setScale(sf::Vector2f(0.6,0.6));
        ErrorText.setPosition(200/6,130/3);
    
    
        while(ErrorBox.isOpen())
        {
            sf::Event Error;
    
    
            {
                while(ErrorBox.pollEvent(Error))
                {
                    if(Error.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                        ErrorBox.close();
                }
            }
    
    
            ErrorBox.draw(ErrorText);
            ErrorBox.display();
        }
    }
    
    
    bool Security::passwords(int passType)
    {
        std::string pass;
    
    
        if(passType == 1)
        {
            std::cout << "Type in your password (MPP ONLY): " << std::endl;
            std::getline(std::cin, pass);
            if( pass == "HelloWorld")
                return true;
            else
                ErrorMsg();
    
    
        }
        else if (passType == 2)
        {
            std::cout << "[Click this window and type in your password]";
            std::cout << "\n\n\n                 Type in your password (Teachers and Students): " << std::endl << std::endl;
            std::cout << "        password: ";
            std::cout << "  " ;
            std::getline(std::cin,pass);
    
    
            if (checkPassword(pass))
                return true;
            else
                ErrorMsg();
        }
    
    
        return false;
    }
    
    
    bool Security::checkPassword(std::string password)
    {
    
    
        passwordArray[0] = "12345";
    
    
        for(int i =0;i<1500;i++)
        {
            if(password == passwordArray[i])
                return true;
        }
    }
    
    
    
    line 45 : error: expected unqualified-id before 'namespace'
    line 89 : error: expected '}' at end of input|
    line 89 : error: expected unqualified-id at end of input|

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The problem probably lies in Security.h.
    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

  3. #3
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77
    Thanks. One more question; I'm having problem with making something like a "serial key". Something like just simply storing strings somewhere in the code and then use if statement to check valid password, and say that I'm the one who gives out the password. How can I do this without hard-coding? Do you know any method of doing so?

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You're generally better off putting the includes for standard things such as iostream before your own header files. That way you've unlikely to screw up anything in the compilation of standard libs.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Passwords usually come down to running with whatever is input. I mean, the password is never compared at all. If it is the right password, it should decrypt whatever you are trying to keep secret.

  6. #6
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by iMalc View Post
    You're generally better off putting the includes for standard things such as iostream before your own header files. That way you've unlikely to screw up anything in the compilation of standard libs.
    Including your own header files before the standard ones has the advantage that you are more likely to make the inclusion dependency correct. If you include standard headers first, you may often forget to include them properly in the other header files. If file Foo.cpp includes its corresponding header Foo.hpp first, it automatically ensures that every standard header is properly included (or else it will not compile). Then you can be sure that someone who includes your Foo.hpp, without including anything else, will not run into something-not-included problem. Precompiled headers make it a bit harder, but you can always turn them off temporarily to check your include directives.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by kmdv View Post
    Including your own header files before the standard ones has the advantage that you are more likely to make the inclusion dependency correct. If you include standard headers first, you may often forget to include them properly in the other header files. If file Foo.cpp includes its corresponding header Foo.hpp first, it automatically ensures that every standard header is properly included (or else it will not compile). Then you can be sure that someone who includes your Foo.hpp, without including anything else, will not run into something-not-included problem. Precompiled headers make it a bit harder, but you can always turn them off temporarily to check your include directives.
    Actually that too is entirely correct. There is no perfect solution.
    Although, something to randomise the order of header inclusions every time you build would be quite interesting.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Meerul264 View Post
    Thanks. One more question; I'm having problem with making something like a "serial key". Something like just simply storing strings somewhere in the code and then use if statement to check valid password, and say that I'm the one who gives out the password. How can I do this without hard-coding? Do you know any method of doing so?
    Typically one have a system where one can create passwords, storing them in some sort of database.
    This goes without saying, but all your passwords should be encrypted with non-symmetric keys (one way passwords).
    Then encrypt the inputted password if you must compare it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird Error
    By elwad in forum C Programming
    Replies: 9
    Last Post: 08-29-2009, 02:41 PM
  2. Weird error
    By elwad in forum C Programming
    Replies: 4
    Last Post: 05-20-2009, 09:34 AM
  3. Weird Error
    By DanFraser in forum C# Programming
    Replies: 3
    Last Post: 01-06-2006, 06:59 AM
  4. Weird error
    By Mithoric in forum Windows Programming
    Replies: 8
    Last Post: 06-06-2004, 01:11 AM
  5. Weird IE error
    By Ravage in forum Tech Board
    Replies: 16
    Last Post: 03-31-2003, 11:46 AM