I have some errors LNK2019 with my homework, but I can't solve it.

My error

Error 7 error LNK2019: unresolved external symbol "void __cdecl input(int * &,int &,class std::basic_ifstream<char,struct std::char_traits<char> > &)" (?input@@YAXAAPAHAAHAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@@Z) referenced in function _main E:\Ex\Bai_1_No_File\main.obj Bai_1_No_File

This is my code.

main.cpp

#include "function.h"
#include <conio.h>
#include <fstream>
#pragma comment


void main()
{
    int* pi=NULL;
    int n;
    bool t=true;
    ifstream fin("in.txt");
    ofstream fou("out.txt");

    while (t==true)
    {
        system("cls");
        cout<<" 1 . input an array"<<endl;
        cout<<" 2 . print an array"<<endl;
        cout<<" 3 . find an integer"<<endl;
        cout<<" 4 . print an ascending array"<< endl;
        cout<<" 5 . exit"<< endl;
        int z;
        cout<<" your selection : ";
        cin>>z;

        if (z<1 || z>5)
        {
            cout<<"Your selection is wrong. Please press anykey to try again!!!";
            fou<<"Your selection is wrong. Please press anykey to try again!!!"<<endl;
            getch();
        }
        else
            if (z==5)
            {
                t=false;
            }
            else
                if (pi==NULL && z!=1)
                {
                    cout<<"There is't an array in the memory please input"<<endl;
                    fou<<"There is't an array in the memory please input"<<endl;
                    cout<<"Press anykey to continue";
                    getch();
                }
                else
                {
                    switch (z)
                    {
                    case 1:
                        {
                            input(pi,n,fin); // read from file
                            break;
                        }
                    case 2:
                        {
                            print(pi, n,fou);
                            getch();
                            break;
                        }
                    case 3:
                        {
                            int x;
                            if (findNumber(pi,n,x)==true)
                            {
                                cout<<"Yes"<<endl;
                                cout<<"integers bigger : "<<endl;
                                fou<<"Yes"<<endl;
                                fou<<"integers bigger : "<<endl;
                                printIntBigger(pi,n,x);
                            }
                            else
                            {
                                cout<<"No"<<endl;
                                fou<<"No"<<endl;
                            }
                            getch();
                            break;
                        }
                    case 4:
                        {
                            printIntAscending(pi,n);
                            print(pi,n,fou);
                            getch();
                            break;
                        }
                    }
                }

    }

    if (pi!=NULL)
    {
        delete []pi;
    }

    fou.close();

};

function.h

#ifndef _HAM_
#define _HAM_
#include <fstream>
#include <iostream>
using namespace std;

void input(int* &pi, int& n, ifstream &fin);
void print(int* pi,int n, ofstream &fou);
bool findNumber(int* pi,int n, int& x);
void printIntBigger(int* pi,int n,int x);
void swap(int& x, int& y);
void printIntAscending(int* pi,int n);
#endif 

function.cpp

#include "function.h"


void input(int* &pi,int& n, fstream &fin)
{
    if (pi!=NULL)
    {
        delete pi;
    }
    fin>>n;
    pi = new int[n];
    if (pi[0]!=NULL)
    {
        for (int i=0; i<n; i++)
        {
            fin>>pi[0];
        }
    }
    fin.close();
};

void print(int* pi, int n, fstream &fou)
{
    for (int i=0; i<n; i++)
    {
        cout<<pi[i]<<" ";
        fou<<pi[i]<<" ";
    }
    fou<<endl;
};

bool findNumber(int* pi,int n, int& x)
{
    cout<<"input an integer : ";
    cin>>x;

    for (int i=0; i<n; i++)
    {
        if (pi[i]==x)
            return true;
    }
    return false;
};

void printIntBigger(int* pi,int n,int x)
{
    for (int i=0; i<n ; i++)
    {
        if (pi[i]>x) 
            cout<<pi[i]<<" ";
    }
};

void swap(int& x, int& y)
{
    int t;
    t=x;
    x=y;
    y=t;
};

void printIntAscending(int* &pi,int n)
{
    int i=0;
    while (i<n-1)
    {
        i=0;
        for(int j=0; j<n-1; j++)
        {
            if (pi[j]>pi[j+1])
                swap(pi[j],pi[j+1]);
            else
                i++;
        }
    }
};

Try adding to main.cpp

#include <iostream>
using namespace std;

If not solve issue, tell what Compiler/IDE and OS/Version you use.

There's some evil inconsistency ...

In function.h, you declare:

void input(int* &pi, int& n, ifstream &fin);

whereas, in function.cpp you have:

void input(int* &pi,int& n, fstream &fin)

i.e., ifstream vs. fstream.

It isn't work.
I use Visual Studio 2012 version 11.0.50727.1.

thank you very much.
I was very careless.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.