0

Hello everybody,

Ran into a bit of trouble! During compilation I get the following error:

fatal error C1083: Cannot open include file: 'login.h': No such file or directory

The login.h does exist in my directory folder.

Please let me know where I have gone wrong.

I am attaching the following files:
lib_test.cpp
login.h

Attachments
#define NOMINMAX // NOMINMAX constant used in order to use the numeric values in the C++ std library

//
#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
#include <limits>
#include "login.h"
#include "read.h"
#include "search.h"
#include "create.h"
#include "edit.h"
#include "view.h"
#include "create.h"
#include "exit.h"
#include "options.h"
#include "include.h"
#include "menu.h"

//
using namespace std;

//Class for Login 
class Login
{
private:
	int login();
};

//Class for Menu
class Menu
{
public:
	void printMenu(), options(int ans);
private:
	int ans;
};

//Class for Library
class library
{
private:
	int main();
};

//Class for Viewing the File
class View
{
public:
	void viewFile();
};

//Class for Viewing the Options
class Options
{
public:
	void options(int ans);
};

//Class for Creating the File
class Create
{
public:
	void createFile();
};

//Class for Reading the File
class Read
{
public:
	void readFile();
};

//Class for Exiting
class Exit
{
public:
	void exitScreen();
};

//Class for Editing a File
class Edit
{
public:
	void editFile();
};

//Class for Searching a File
class Search
{
public:
	void searchFile();
};

//Function for Login
int login()
{
	string username; //This is a string variable calld username(string variables r 4 saving text)
	string password; //this is a string variable calld password
	int tries = 3;       //This is a integer variable tries.Here we save the number of tries to ques the
	

	//username and password(integer = 4 saving numbers not decimal numbers).And we set it on 0

	while(tries)
	{
		cout << "Username: "; //displays Username: on the screen
		cin >> username; //Saves the input in the variable username
		cout << "Password: "; 
		cin >> password;

		if(username == "admin" && password == "password") //if username is the same as Admin and password is the
		//If password is correct then:
		{
			system("cls"); //clear screen
			cout << "Welcome to the Library System! \n";
			cout << "_______________________________\n";
			printMenu();
			system("pause");
			return 0;
			
		}
		else 
		{
			tries--; //tries + 1
		}
				
	}
	return -1;
};


void printMenu(), options(int ans);

void printMenu()
{
     int ans;
	 do
     {
		  cout << "\nPlease choose from the following options:\n\n";
          cout << "-------------------------------------------\n\n";
		  cout << "1: Search for a file\n\n";
		  cout << "2: Create a new file\n\n";
		  cout << "3: View entire catalogue\n\n";
		  cout << "4: Exit from the program\n\n";
		  cout << "-------------------------------------------\n\n";
          cin  >> ans;
          cin.ignore(80,'\n');
          options(ans);
	 }
	 while(ans!=4);
};

int main()
{	
	int success=0;
	login();
	
	if (success = 0)
	{
		cout << "Invalid Username and Password!\n";
		return -1;
		
	}
	else 
	{
		
		return 0;
		
	}
	
		
};


void viewFile()
{
	cout << "\nFull catalogue: \n";

	readFile();
};

void options(int ans)
{
     switch (ans)
     {
			case 1:                         
               searchFile();
               break;
			case 2:
               createFile();
               break;
			case 3:
               viewFile();
               break;
			case 4:
               exitScreen();
               break;
			default:
               cout << "Please select an available option\n\n";
               break;
     }
};

void createFile()
{
	char author[30], title[124], fileName[40];
	int id;
    
    cout << "\nEnter the Author: ";
    cin >> author;
    cout << "Enter the book title: ";
    cin >> title;
    
	cout << "Enter I.D.: ";
	cin >> id;
	
	ofstream ID( "id.txt", ios::app );
	ID << "\n" << id;
	

	cout << "\nEnter the name of the file you want to create: ";
    cin >> fileName;
    
    ofstream Book(fileName, ios::out);
	Book << "Author: " << author << "\n" << "Title: " << title << "\n" << "I.D. Number: " << id;

};

void readFile()
{
	string line;
	ifstream myfile ("id.txt");
	if (myfile.is_open())
	{
		while (! myfile.eof() )
		{
			getline (myfile,line);
			cout << line << endl;
		}
	myfile.close();
	}
else cout << "Unable to open file"; 
};

void exitScreen()
{
	std::cout << "\n\nPress Enter to exit...";
    std::cin.clear();
    std::cin.sync(); 
	std::cin.ignore( std::numeric_limits <std::streamsize> ::max(), '\n' );

};

void editFile()
{
	cout << "\nThe file contains: \n";
	readFile();

	char buffer[1024]; 
	ofstream outonly; 
	
	outonly.open( "id.txt", ios::app );
	
	cout << "\nPlease add your new data: \n";
	cout << ", press RETURN on an empty ";
	cout << "line to quit.\n\n";
	do
	{
		cin.getline(buffer, 1023);
		outonly << buffer << endl;
	}
	while(*buffer);
};

void searchFile()
{
	char nam[40];
	cout << "\nPlease enter the file name you are looking for\n\n"; cin >> nam;
	Sleep(2500);
					
    string line;
	ifstream myfile (nam);
	if (myfile.is_open())
	{
		cout << "\nThe file contains\n\n";
		while (! myfile.eof() )
		{
			getline (myfile,line);
			cout << line << endl;
		}
	myfile.close();
	}
	else cout << "\n\nThis file does not exist you will have to create a new one\n\n"; 
	cout << "\n\n";
	system("pause");
	cout << "\n";
};
#pragma once //causes the current source file to be included only once in a single compilation

#include "include.h"
#include "exit.h"
#include <iostream>


int login()
{
	string username; //This is a string variable calld username(string variables r 4 saving text)
	string password; //this is a string variable calld password
	int tries = 3;       //This is a integer variable tries.Here we save the number of tries to ques the
	

	//username and password(integer = 4 saving numbers not decimal numbers).And we set it on 0

	while(tries)
	{
		cout << "Username: "; //displays Username: on the screen
		cin >> username; //Saves the input in the variable username
		cout << "Password: "; 
		cin >> password;

		if(username == "admin" && password == "password") //if username is the same as Admin and password is the
		//If password is correct then:
		{
			system("cls"); //clear screen
			cout << "Welcome to the Library System! \n";
			cout << "_______________________________\n";
			printMenu();
			system("pause");
			return 0;
			
		}
		else 
		{
			tries--; //tries + 1
		}
				
	}
	return -1;
}
2
Contributors
11
Replies
12
Views
7 Years
Discussion Span
Last Post by rEhSi_123
0

just as well you got that error because NEVER EVERY UNDER NO CIRCUMSTANCES put executable code in a header file (inline functions are the only exception.) Take that function out of that *.h file and put it in a *.cpp file. Then compile the two *.cpp files separately and link the object files together. Exactly how to do that will depend on the compiler you are using.

0

just as well you got that error because NEVER EVERY UNDER NO CIRCUMSTANCES put executable code in a header file (inline functions are the only exception.) Take that function out of that *.h file and put it in a *.cpp file. Then compile the two *.cpp files separately and link the object files together. Exactly how to do that will depend on the compiler you are using.

I am using MS VC++ 2008 Express version.

I did exactly what you said.

It is showing the exact same error again twice......

This error is in the include.h file

fatal error C1083: Cannot open include file: 'login': No such file or directory

fatal error C1083: Cannot open include file: 'login': No such file or directory

Now, Do you suggest to change all my .h file to .cpp?

Attachments
#pragma once //causes the current source file to be included only once in a single compilation

#include <iostream>
#include <fstream>
#include <string>
#include <limits>
#include <login>

using namespace std;
0

So -- where is <login> header file? Is that the same file you posted previously but as login.h? If it is, it belongs in the same folder as the other *.cpp files in the project.

>>Now, Do you suggest to change all my .h file to .cpp?'
Not at all -- only the ones with executable code.

0

All the files are in the folder.
But still it is failing to find the file

0

1) in login.cpp change #include <login> to #include "login.h" 2) in include.h, change #include <login.h> to #include "login.h" When surrounded by angle brackets < and > the compiler does not look in the project directory for include files. You have to put it in quotes to do that.

After you fix that you will get a lot of other errors.

0

1) in login.cpp change #include <login> to #include "login.h" 2) in include.h, change #include <login.h> to #include "login.h" When surrounded by angle brackets < and > the compiler does not look in the project directory for include files. You have to put it in quotes to do that.

After you fix that you will get a lot of other errors.

Well Yeah.....20 errors in total.....which includes an include file error??

0

Well Yeah.....20 errors in total.....which includes an include file error??

Nope -- here are the errors I get. As you can see, the first error is about undefined symbol "printMenu". Fix that up and recompile. I'm not going to fix all the errors in this program for you -- that is for you to do.

1>c:\dvlp\tmp\lib_test\lib_test\login.h(31) : error C3861: 'printMenu': identifier not found
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(99) : error C2084: function 'int login(void)' already has a body
1> c:\dvlp\tmp\lib_test\lib_test\login.h(9) : see previous definition of 'login'
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(138) : error C2084: function 'void printMenu(void)' already has a body
1> c:\dvlp\tmp\lib_test\lib_test\menu.h(7) : see previous definition of 'printMenu'
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(159) : error C3861: 'login': identifier not found
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(179) : error C2084: function 'void viewFile(void)' already has a body
1> c:\dvlp\tmp\lib_test\lib_test\view.h(7) : see previous definition of 'viewFile'
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(186) : error C2084: function 'void options(int)' already has a body
1> c:\dvlp\tmp\lib_test\lib_test\menu.h(7) : see previous definition of 'options'
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(196) : error C3861: 'viewFile': identifier not found
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(208) : error C2084: function 'void createFile(void)' already has a body
1> c:\dvlp\tmp\lib_test\lib_test\create.h(9) : see previous definition of 'createFile'
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(233) : error C2084: function 'void readFile(void)' already has a body
1> c:\dvlp\tmp\lib_test\lib_test\read.h(6) : see previous definition of 'readFile'
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(249) : error C2084: function 'void exitScreen(void)' already has a body
1> c:\dvlp\tmp\lib_test\lib_test\exit.h(8) : see previous definition of 'exitScreen'
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(258) : error C2084: function 'void editFile(void)' already has a body
1> c:\dvlp\tmp\lib_test\lib_test\edit.h(10) : see previous definition of 'editFile'
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(260) : error C3861: 'readFile': identifier not found
1>c:\dvlp\tmp\lib_test\lib_test\lib_test.cpp(279) : error C2084: function 'void searchFile(void)' already has a body
1> c:\dvlp\tmp\lib_test\lib_test\search.h(9) : see previous definition of 'searchFile'
1>login.cpp
1>c:\dvlp\tmp\lib_test\lib_test\login.h(11) : error C2065: 'string' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(11) : error C2146: syntax error : missing ';' before identifier 'username'
1>c:\dvlp\tmp\lib_test\lib_test\login.h(11) : error C2065: 'username' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(12) : error C2065: 'string' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(12) : error C2146: syntax error : missing ';' before identifier 'password'
1>c:\dvlp\tmp\lib_test\lib_test\login.h(12) : error C2065: 'password' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(20) : error C2065: 'cout' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(21) : error C2065: 'cin' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(21) : error C2065: 'username' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(22) : error C2065: 'cout' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(23) : error C2065: 'cin' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(23) : error C2065: 'password' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(25) : error C2065: 'username' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(25) : error C2065: 'password' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(29) : error C2065: 'cout' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(30) : error C2065: 'cout' : undeclared identifier
1>c:\dvlp\tmp\lib_test\lib_test\login.h(31) : error C3861: 'printMenu': identifier not found
1>c:\dvlp\tmp\lib_test\lib_test\login.cpp(10) : error C2084: function 'int login(void)' already has a body
1> c:\dvlp\tmp\lib_test\lib_test\login.h(9) : see previous definition of 'login'
1>c:\dvlp\tmp\lib_test\lib_test\login.cpp(31) : error C3861: 'printMenu': identifier not found

0

Nope -- here are the errors I get. As you can see, the first error is about undefined symbol "printMenu". Fix that up and recompile. I'm not going to fix all the errors in this program for you -- that is for you to do.

WOW! petty i never got so many errors;)

Anyhow brother I recreated my project in VC++ and avoided having so many .h files to which I realised I didn't needed to! So instead created on whole .cpp file with all the classes and functions.

Anyways thanks for all the support.

Cheers

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.