Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
main.cpp

C++
#include "Login.h"

int main () {
    Loginf();
}


Login.h

C++
#ifndef LOGIN_H
#define LOGIN_H
#include <string>
#include <iostream>

using namespace std;

void Loginf ();


class Login
{
public:

    Login ();
    string getInput () {
        return input;
    }
    void setInput (string x) {
        x=input;
    }
private:
    string input;
};

#endif


Login.cpp

C++
#include "Login.h"


Login::Login () {};

void Loginf () {
    Login lo;
    lo.setInput("hello");
    cout << lo.getInput();
};


A simple program that i started with to display an input to the screen. However, when i build it, all i get is this:

mingw32-g++.exe  -o "bin\Debug\first project.exe" include\Login.h.gch obj\Debug\main.o obj\Debug\src\Login.o
include\Login.h.gch: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))


I have no idea why its giving me this. The reason for this program is to figure out how to use header files with functions prototypes and a class with an object so that i can create a program with a simple login. So, I need to keep the function and the class, I don't want to have to simply define the function in main or something like that.

So my question, to sum this up, is simply: why won't this code run, and what can I do to fix it without changing the format (main.cpp calls the function, login.h prototypes it and creates the class, login.cpp defines the function).
Posted
Updated 12-Sep-14 14:34pm
v2
Comments
Sergey Alexandrovich Kryukov 12-Sep-14 20:29pm    
Sorry, but 3nd and 4th lines of login.h say
#include
#include


That said, you first need to show actual code, the code which compiles and shows the problem. You did not even show the entry-point function...

—SA
Member 11078975 12-Sep-14 20:32pm    
Huh thats weird that didnt show up when i copied it over, but what i actually have for Login.h is:

#ifndef LOGIN_H
#define LOGIN_H
#include <string>
#include <iostream>

using namespace std;

void Loginf ();


class Login
{
public:

Login ();
string getInput () {
return input;
};
void setInput (string x) {
x=input;
};
private:
string input;
};

#endif
PIEBALDconsult 12-Sep-14 20:35pm    
He didn't encode the angles. Fixed.
Sergey Alexandrovich Kryukov 12-Sep-14 21:12pm    
Thank you. I put some answer...
—SA
[no name] 12-Sep-14 20:31pm    
http://www.mingw.org/wiki/MinGW_for_First_Time_Users_HOWTO

I'm not familiar with mingw, but the reference to include\Login.h.gch indicates that Login.h is being used as a precompiled header. It doesn't look like you intended it to be used as a precompiled header however! I suggest you check the project settings and properties. Either disable the use of precompiled headers, or read up on how to use them properly and fix the settings and contents of your precompiled header definition.
 
Share this answer
 
v2
Comments
CPallini 15-Sep-14 2:48am    
Good point.
First thing that caught my eye: the function setInput does nothing. It assigns the value to a by-value string parameter, and the effect of this assignment is lost on exit. Probably, you meant to assign
C++
input = x;

—SA
 
Share this answer
 
Comments
Member 11078975 12-Sep-14 23:04pm    
oh yes thank you i forgot that = is an assignment not an equal sign :(
Member 11078975 12-Sep-14 23:06pm    
still didnt run though same problem
Sergey Alexandrovich Kryukov 12-Sep-14 23:23pm    
No, no, everything in your code says that you really need the assignment. With equality comparison operator, the code would have even less sense (only if it would be possible to make less than zero sense :-).
—SA
Member 11078975 13-Sep-14 0:12am    
Ya i meant i forgot that it wasnt an equal sign. What i meant by that is i didnt realize that
x = input;
input = x;

Are two different things, because its an assignment, not an equal sign. If it was an equal sign, they would simply equal each other and the order wouldn't matter, but I failed to remember that it would because its an assignment.
Sergey Alexandrovich Kryukov 13-Sep-14 9:46am    
I see...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900