for many times when i debuge defferent programs i found this error.
I think no error in my code because when i degun the same program in ma freids computer no wrong happen.

Any idea.
the errors:
1- fatal error LNK1120: 1 unresolved external.

2- error LNK2019: unresolved external symbol "void __cdecl ReadData(int * const,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * const,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * const,float * const,int * const)" (?ReadData@@YAXQAHQAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1QAM0@Z) referenced in function _main HW2_82032.obj

Recommended Answers

All 30 Replies

Smells like linker error! Are you messing with libraries? Does your program need one?

Also seems English is not native for you. ;)

Smells like linker error! Are you messing with libraries? Does your program need one?

Also seems English is not native for you. ;)

actually I included all the libraries that i need them. I am sure of this.

I am tring to be good in english:D


thanks

what does fatal error means >?????

actually I included all the libraries that i need them. I am sure of this.

No, you didn't. that is why the linker complains.
Which IDE do you use?

I am tring to be good in english:D


thanks

:)

what does fatal error means >?????

error that will end up killing your application

No, you didn't. that is why the linker complains.
Which IDE do you use?


:)

what do u mean about IDE???

i included these libraries:

#include<iostream> //for i/o
#include<fstream> //for opening files
#include<string> //for strings
#include<iomanip>

when i compile my program >>> NO errors N0 warnings

but when i debug it , the errors appears????

i included these libraries:

#include<iostream> //for i/o
#include<fstream> //for opening files
#include<string> //for strings
#include<iomanip>

Where does ReadData() come from then? I don't think that's included with any of these.

How are you compiling the code?

Are you using manual commands from command line or are you using any Development Environment?

Would it be possible for you to post the exact command used for compilation?

Hi...could you please put up the program??
Thanks.

Also, highlight the first line in your errors and it usually it the set of to the majority of your errors.

This is my code:

/*  This program is demonstrates the understanding of file management and using array with simple data.The general
idea of this HW is to rovide a selected options and prompt the user to choose one option from 1-4. These options 
provide different information about student from science college. The options are : 1-find student data and output 
it to screen. 2- add new student information. 3- delete specifice student data from the file. 4-print a report of 
all student data on screen and output data file.  */

#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
void ReadData( int[], string[] , string[] ,float[],int[] );      //prototypes
int DisplayMenu(int);        void FindStud(int);
void AddStud(int);           void DeleteStud(int);
//void StopPrint(int[]);    //void SearchData(int[]);
int option;
int nums=0;

int main()
{  int ID;
   int SID[50];  int HRS[50] ;  string FNAME[50];  string MAJOR[50] ; float GPA[50];  //char Del[50];
   ifstream myfile;
   myfile.open("StudInput.txt");
   myfile>>SID[0]>>FNAME[0]>>MAJOR[0]>>GPA[0]>>HRS[0];
   ReadData( SID,FNAME,MAJOR,GPA,HRS );     

   cout<<setw(5)<<" Student Information System \n"<<cout<<setw(5)<<" Comp 2102, Assignment 2 \n\t"
   <<cout<<"Fall 2009 \n\n"<<cout<<setw(5)<<"1. Find Student Data\n"<<cout<<setw(5)<<"2. Add New Student Data\n"
   <<cout<<setw(5)<<"3. Delete Student Data\n"<<cout<<setw(5)<<"4. Stop and Print the report\n\n";
   cout<<setw(5)<<" Enter your option : ";
   cin>>option;    
  
  DisplayMenu(option);

  if(option==1)
     {  cout<<" Enter the id: \n";
        cin>>ID;
	    FindStud(ID);    }
  else if (option==2)
      { cout<<" Enter the id: \n";
        cin>>ID;
		AddStud(ID);    }
  else if(option==3)
       {   cout<<" Enter the id: \n";
            cin>>ID;
		    DeleteStud(ID);  }
 /* else
       {  StopPrint  }  */

 //SearchData();
return 0;
}


//********************************************************************************************
void ReadData(int SID[],string FNAME[],string MAJOR[],float GPA[],float HRS[])
{  ifstream myfile;
   while(myfile)
   { nums++;
	myfile>>SID[nums]>>FNAME[nums]>>MAJOR[nums]>>GPA[nums]>>HRS[nums];
   }//end loop
myfile.close();
}//end function


//**********************************************************************************************
int DisplayMenu(int option)
{   cout<<"hii"<<endl;
	while(cin)
	{  cout<<"hello"<<endl; 
	      if ( (option <1) || (option>4)  )
	      {   cout<<endl<<" Your option is out of range "<<endl;
              cout<<setw(5)<<"1. Find Student Data\n"<<cout<<setw(5)<<"2. Add New Student Data\n"
              <<cout<<setw(5)<<"3. Delete Student Data\n"<<cout<<setw(5)<<"4. Stop and Print the report\n\n";
              cout<<setw(5)<<" Enter your option : ";
              cin>>option;   }//end if
	     else
		   break;
	}//end loop
return option;
}

//************************************************************************************************************
void FindStud( int ID)
{	int SID[50];  int HRS[50] ;  string FNAME[50];  string MAJOR[50] ; float GPA[50]; //  char Del[50];
    bool flag=false;   int n=200;  
    ifstream infile;
	infile.open("StudInput.dat");   cout<<" hello again1"<<endl;
	int nums=100;  
	 while(cin)
	{   cout<<" hello again2"<<endl;
		for ( int m=0; m<nums; m++ )
        {   cout<<" hello again3"<<endl;
		       if( SID[m]==ID)
			   {  cout<<setw(5)<<" Student Id: "<<setw(5)<<SID[m]<<endl;
			      cout<<setw(5)<<" First Name: "<<setw(5)<<FNAME[m]<<endl;
				  cout<<setw(5)<<" Major: "<<setw(5)<<MAJOR[m]<<endl;
				  cout<<setw(5)<<" Gpa: "<<setw(5)<<GPA[m]<<endl;
				  cout<<setw(5)<<" Total Credits: "<<setw(5)<<HRS[m]<<endl;
			      flag=true;
			       break;
			  }//end if
        }//end for loop
	infile.close();
	if(!flag)
		   cout<<" ID was not found "<<endl;
	cout<<" Enter the id: "<<endl;
    cin>>ID;
  }//end loop	
}// end function find stud


//*********************************************************************************************************
void AddStud(int ID)
{   int SID[50];  int HRS[50] ;  string FNAME[50];  string MAJOR[50] ; float GPA[50]; // char Del[50];
    ifstream infile;
	infile.open("StudInput.dat");
	int nums=0; int id ;
	cout<<" Enter the id: "<<endl;
    cin>>ID;
    while(cin)
	{   for ( int m=0; m<nums; m++ )
        {     if( SID[m]==ID)
			     {  cout<<"***Error*** the student already exist. ";
	                   cout<<"Enter 1 to provide another id or 0 to go to the menu: ";
					   cin>>id;
                        
					   if(id==0)
					   {      cout<<setw(5)<<" Student Information System \n"<<cout<<setw(5)<<" Comp 2102, Assignment 2 \n\t"
                               <<cout<<"Fall 2009 \n\n"<<cout<<setw(5)<<"1. Find Student Data\n"<<cout<<setw(5)<<"2. Add New Student Data\n"
                               <<cout<<setw(5)<<"3. Delete Student Data\n"<<cout<<setw(5)<<"4. Stop and Print the report\n\n";
                               cout<<setw(5)<<" Enter your option : ";
                              cin>>option;
					          DisplayMenu(option); break;    }//end if id=0
					   if(id==1)
					   {       cout<<" Enter Student Id:    ";          cin>>SID[5];
                          	    cout<<endl<<" Enter First Name:    ";    cin>>FNAME[5];
                                cout<<endl<<" Enter  Major:    ";    cin>>MAJOR[5];
	                            cout<<endl<<" Enter Gpa:    ";    cin>>GPA[5];
	                            cout<<endl<<" Enter Total Credits:    ";    cin>>HRS[5]; 
								cout<<"*** Data Added ***"<<endl;
					      break;   }//end if(id==1)
	             }//end if ( SID[m]==ID)
	    }//end for loop	
    cout<<endl<<" Enter Student Id:    ";          cin>>SID[5];
	cout<<endl<<" Enter First Name:    ";    cin>>FNAME[5];
    cout<<endl<<" Enter  Major:    ";        cin>>MAJOR[5];
	cout<<endl<<" Enter Gpa:    ";           cin>>GPA[5];
	cout<<endl<<" Enter Total Credits:    "; cin>>HRS[5];
    cout<<"*** Data Added ***"<<endl;
	infile.close();
	}//end while loop
}//end  function



//**********************************************************************************************
void DeleteStud(int ID)
{   int SID[50];  
	ifstream infile;
	infile.open("StudInput.dat");
	int nums=0;  
	cout<<" Enter the id: "<<endl;
    cin>>ID;
    while(cin)
	{   for ( int m=0; m<nums; m++ )
        {    if( SID[m]==ID)
			     {  SID[m]=0;
	                 break;}//end if ( SID[m]==ID)
	    }//end for loop	
    cout<<"ID was not found"<<endl; 
	}//end while
infile.close();
}//end function

Error : fatal error LNK1120: 1 unresolved external
this error in line 1 ?? how it come ??

How are you compiling the code?

Are you using manual commands from command line or are you using any Development Environment?

Would it be possible for you to post the exact command used for compilation?

soory i didntunderstand what u mean.

i posted the code . u can have a look


thank you

Hi...could you please put up the program??
Thanks.

Also, highlight the first line in your errors and it usually it the set of to the majority of your errors.

i posted the code.

thanks

Issue is data type mismatch.

prototype is

void ReadData( int[], string[] , string[] ,float[],int[] );

implementation is

void ReadData(int SID[],string FNAME[],string MAJOR[],float GPA[],float HRS[])

Either pass an array of floats to the function and change the prototype as well

or change the implementation to take an array of integers for HRS.

Issue is data type mismatch.

prototype is

void ReadData( int[], string[] , string[] ,float[],int[] );

implementation is

void ReadData(int SID[],string FNAME[],string MAJOR[],float GPA[],float HRS[])

Either pass an array of floats to the function and change the prototype as well

or change the implementation to take an array of integers for HRS.

u are right > thank you
i solverd the error now.:icon_smile:
but still errors on while loop.

i will work in option 1: if i have any problems . i willcome back again:)

i separated my code in small programs.
i posted the read function program only to check
if the program read the data in txt file or not .

but my program does not read what is inside the txt file???!!!!


my out put is: -858993460

and it should be like this:

1111 Hamad Comp 3.25 110
5555 Nasir Physics 2.56 85
2222 Laila Math 2.30 89
1200 Amal Comp 1.99 120
4444 Yahia Comp 2.67 56
these data are written in the txt file ( StudInput.txt)

ANY idea what wrong ??

//hw2  comp2102

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void ReadData(int[], string[] , string[] ,float[],float[]);      //prototypes
//void DisplayMenu(int[]);
//void FindStud(int[]);
//void AssStud(int[]);
//void DeleteStud(int[]);
//void StopPrint(int[]);
//void SearchData(int[]);
int main()
{  int SID[50]; float HRS[50] ; string FNAME[50]; string MAJOR[50] ; float GPA[50];  //char Del[50];
   ReadData( SID,FNAME,MAJOR,GPA,HRS );   
   cout<<SID[0]<<"  "<<FNAME[0]<<"  "<<MAJOR[0]<<endl;    //test if the program read the data in txt file
 //DisplayMenu();
 //FindStud();
 // AssStud();
 //DeleteStud();
 //StopPrint();
 //SearchData();
return 0;
}

void ReadData(int SID[],string FNAME[],string MAJOR[],float GPA[],float HRS[])
{ int nums=0;
  ifstream datafile;
  datafile.open("StudInput.dat");
  datafile>>SID[nums]>>FNAME[nums]>>MAJOR[nums]>>GPA[nums]>>HRS[nums];
    while(datafile)
   { nums++;
	datafile>>SID[nums]>>FNAME[nums]>>MAJOR[nums]>>GPA[nums]>>HRS[nums];
   }//end loop
datafile.close();
}

check for error in file opening after opening the file. Take a look here for more info regarding files

the function still does not read from txt file> actually the file is not open
i dont know why ?? i am sured that i created the txt file correctly>

Any suggestions???!!!

Make sure you have a copy of it in the debug directory associated with your project (I assume you are using Visual C++ based on your error message above).
So you'll have a directory called "ProjectName" (fill in your own project name) wherever you saved it. Put the dat file in ProjectName\Debug.

the error still unsolved ???!!!

At the very beginning of the program, open a file names XXX.XXX for writing. Write something (anything) into it. Close the file.

Now search for the file XXX.XXX on disk. When you find it, that is where your input file must be. Move it there.

Delete that new code and try again.

At the very beginning of the program, open a file names XXX.XXX for writing. Write something (anything) into it. Close the file.

Now search for the file XXX.XXX on disk. When you find it, that is where your input file must be. Move it there.

Delete that new code and try again.

i will try again

thank you

the problem solved

i wrote:

myfile.open("G:\\comp2102\\hw 2 = separete fun on prog\\last version\\StudInput.txt");

instead of :

myfile.open("StudInput.txt");

BUT another problem appears:

now main function call ReadData function and return back
and when i tested the code : the problem is that the function does not return the data that are read to the main to display it.

more explanation:

 ifstream myfile;

 myfile.open("G:\\comp2102\\hw 2 = separete fun on prog\\last version\\StudInput.txt");

 myfile>>SID[0]>>FNAME[0]>>MAJOR[0]>>GPA[0]>>HRS[0];
 cout<<SID[0]<<"   "<<FNAME[0]<<"  "<<GPA[0]<<"  "<<MAJOR[0]<<"   "<<HRS[0]<<endl;    //here the output is wright

   ReadData( SID,FNAME,MAJOR,GPA,HRS );       //call function read data

   cout<<" hi i came back after read data fun "<<endl;    // just to test if the execution reached here

   cout<<SID[1]<<"   "<<FNAME[1]<<"  "<<GPA[1]<<"  "<<MAJOR[1]<<"   "<<HRS[1]<<endl;     // the problem is here    no thing is displayed  because i think  the is something wrong in reading data   OR  the function does not return the  values to the main

the function read data:

void ReadData(int SID[],string FNAME[],string MAJOR[],float GPA[],float HRS[]) //function to read data from txt file
{  ifstream myfile;
   while( !myfile.eof() ) //while not end of file
   { nums++;             
    myfile>>SID[nums]>>FNAME[nums]>>MAJOR[nums]>>GPA[nums]>>HRS[nums];  //read first row
   }//end loop
myfile.close();
}//end function

any one help

tomorrow is the due date of the assignment

What is the value of nums when you enter ReadData()? It's probably not what you expect.

And don't be so pushy. 4 minutes is way too short to start bumping. As a matter of fact, bumping is rude and should not be done anyway.

What is the value of nums when you enter ReadData()? It's probably not what you expect.

nums=0
i declared it as glaobal

What's with all the [*]s??? Stop trying to be cute.
Set nums = 0 in the function, not as a global. Keep your values where you need them.

It helps to explain what the problem is, not just tell us there is one. We do't know your program, data file, nor task. Without details we're only guessing -- like I did above.

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.