gives me error

main

/* 
The purpose of this lab is to open a text file and then make 
a copy of it
*/


#include <iostream>
#include <fstream>
#include "Interface.h"
using namespace std;

int main()
{
//open up file to be read from
    string input;
    ifstream in;
    cout<<"enter file name which needs to be opened\n";
    cin>>input;
    in.open(input.c_str());
    while(!in)
    {
        in.close();
        cout<<"the input textfile failed please reenter the file\n";
        in.clear();
        cin>>input;
        in.open(input.c_str());
    }
    cout<<"the file opened\n";
    //open up file to copy to
    string output;
    ofstream out;
    cout<<"enter file name which to copy to\n";
    cin>>output;
    out.open(output.c_str());
    while(!out)
    {
        out.close();
        cout<<"output file opening failed. Please reenter output file name\n";
        out.clear();
        cin>>output;
        out.open(output.c_str());
    }
    copyname a;
//read in data
    a.readinput(in);
//   use f.getline for Cstring and >> for rest...
    return 0;
}

interface

#ifndef INTERFACE_H_INCLUDED
#define INTERFACE_H_INCLUDED
#include <iostream>
using namespace std;
class copyname
{
    public:
    void readinput(ifstream& input);

};

#endif // INTERFACE_H_INCLUDED

implementation

#include "Interface.h"
#include <fstream>

void readinput(ifstream& input)
{
    string name;
    getline(input,name);
    cout<<name; 
}

error in main not sure why though i declare a class than try to call the function.

Edited 3 Years Ago by deceptikon: Snipped personal information at author's request

readinput() is a method of class.

void copyname::readinput(ifstream& input)
{
    string name;
    getline(input,name);
    cout<<name; 
}

it works if i have it in my int main so i must be doing something wrong with the implementation and interface files.

lotrsimp12345,

still gives me same error. but works if i have it in int main

Post error description or message.

already have
here is modified code
main

/* 
The purpose of this lab is to open a text file and then make 
a copy of it reading in name, id number, gpa and grade
*/


#include <iostream>
#include <fstream>
#include "Interface.h"
using namespace std;

int main()
{
//open up file to be read from
    string input;
    ifstream in;
    cout<<"enter file name which needs to be openedn";
    cin>>input;
    in.open(input.c_str());
    while(!in)
    {
        in.close();
        cout<<"the input textfile failed please reenter the filen";
        in.clear();
        cin>>input;
        in.open(input.c_str());
    }
    cout<<"the file openedn";
    //open up file to copy to
    string output;
    ofstream out;
    cout<<"enter file name which to copy ton";
    cin>>output;
    out.open(output.c_str());
    while(!out)
    {
        out.close();
        cout<<"output file opening failed. Please reenter output file namen";
        out.clear();
        cin>>output;
        out.open(output.c_str());
    }

    copyname a;
    //read in data
        a.readinput(in);
    //
    return 0;
}

interface

#ifndef INTERFACE_H_INCLUDED
#define INTERFACE_H_INCLUDED
#include <iostream>
#include <fstream>
using namespace std;
class copyname
{
    public:
    void readinput(ifstream& inputfile);
};

#endif // INTERFACE_H_INCLUDED

implementation

#include "Interface.h"
#include <fstream>
using namespace std;
void copyname::readinput(ifstream& inputfile)
{
    string name;
    getline(inputfile,name);
    cout<<name;
}

Edited 3 Years Ago by deceptikon: Snipped personal information at author&#39;s request

I am sorry. I missed this :

undefiined reference to 'copyname::readinput(std::basic_ifstream<char,std::char_traits...'

It's linker error - readinput().

Which compiler are you using?

codeblocks

1. Select Project Menu + Properties + Build Targets Tab
2. Checked all Build Target files. (three files - interface.h, .cpp ...).

This question has already been answered. Start a new discussion instead.