Hello:

I am practicing with some existing code from the book, but when I go to compile this code I get an error on line 4:


.....cpp(4) : fatal error C1083: Cannot open include file: 'mystack.h': No such file or directory

#include <iostream>
#include <iomanip>
#include <fstream>
#include "mystack.h"

Any suggestions?

Do you have a mystack.h file implemented in the same folder as your main program?

Seems like you're using Microsoft Visual C++ ...

> Did you put the header file in the project ?
> Is the header file in the same directory as the '.cpp' file(s) where you're including it in ?

I have entire C++ code in "Source Files" folder in Visual C++, I didn't put anything in "Header Files" folder. For all the programs I made and played with so far I didn't have to do that, so I am little confused about your directions.

You have to put your header file in the header files folder of your project ...

So how exactly do I do that?

Right hand click on "Header Files" folder, add New Item, choose .h or .cpp and what do I put in here?

So how exactly do I do that?

Right hand click on "Header Files" folder, add New Item, choose .h or .cpp and what do I put in here?

Choose '.h' and then add your header file: 'mystack.h' ...

Choose '.h' and then add your header file: 'mystack.h' ...

So here is what I have done so far:

I added newitem to HeadFile folder and named it same as my cpp, but with extension .h and only have the following in .h file:

#include "mystack.h"

It still doesn't work.

Could you please post your code ?

Could you please post your code ?

#include <iostream>
#include <iomanip>
#include <fstream>
#include "mystack.h"

using namespace std;

void evaluateExpression (ifstream& inpF, ofstream& outF, stackType <double>& stack, char& ch, bool & isExpOk);
void valuateOpr (ofstream& out, stackType<double>& stack, char& ch, bool& isxpOk);
void discardExp (ifstream& in, ofstream& out, char& ch);
void printResult (ofstream& outF, stackType<double>& stack, bool isExpOk);

int main()
{ 
	bool expressionOk;
	char ch;
	stackType<double> stack (100);
	ifstream infile;
	ofstream outfile;

	infile.open("C:\\temp\\data.txt");
	outfile<<fixed<<showpoint:
	outfile<<setprecision(2);

	infile>>ch;
	while (infile)
	{
		stack.initializeStack();
		expressionOk=true;
		outfile<<ch;
		evaluateExpression (infile, outfile, stack, ch, expressionOk);
		printResult(outfile, stack, expressionOk);
		infile>>ch;
	}

	infile.close();
	outfile.close();
	return 0;
}

void evaluateExpression (ifstream& inpF, ofstream& outF, stackType <double>& stack, char& ch, bool & isExpOk)
{
	double num;
	while (ch!='=')
	{
		switch (ch)
		{
		case '#':
			inpF>>num;
			outF<<num<<" ";
			if (!stack.isFullStack())
				stack.push(num);
			else
			{
				cout<<"Stack overflow."<<"Program terminates!"<<endl;
				exit (0);
			}
			break;
		default:
			evaluateOpr(outF, stack, ch, isExpOk);
		}
		if (isExpOk)
		{
			inpF>>ch;
			outF<<ch;
			if (ch!='#')
				outF<<" ";
			else
				discardExp (inpF, outF, ch);
		} 
	}

	
	void valuateOpr (ofstream& out, stackType<double>& stack, char& ch, bool& isExpOk)
	{
		double op1, op2;
		if (stack.isEmptyStack())
		{
			out<<" (Not enough operands)";
			isExpOk=false;
		}
		else
		{
			op2=stack.top();
			stack.pop();

			if (stack.isEmptyStack())
			{
				out<<" (Not enough operands)";
				isExpOk=false;
			}
			else
			{
				op1=stack.top();
				stack.pop();

				switch (ch)
				{
				case '+':
					stack.push(op1+op2);
					break;

				case '-':
					stack.push (op1-op2);
					break;
				
				case '*':
					stack.push(op1*op2);
					break;
				
				case '/':
					if (op2!=0)
					stack.push(op1/op2);
					else
					{
					out<<" (Division by 0)";
					isExpOk=false;
					}
					break;

				default:
					out<<" (Illegal operator)";
					is ExpOk=false;
				}
			}
		}
	}

void discardExp (ifstream& in, ofstream& out, char& ch)
{
	while (ch!='=')
	{
		in.get(ch);
		out<<ch;
	}
}

void printResult (ofstream& outF, stackType<double>& stack, bool isExpOk)
{
	double result;
	if (isExpOk)
	{
		if(!=stack.isEmptyStack())
		{
			result=stack.top();
			stack.pop();
			if (stack.isEmptyStack())
				outF<<result<<endl;
			else
				outF<<" (Error: Too man operands)"<<endl;
		}
		else outF<<" (Error in the expression)"<<endl;
	}
	else outF<<" (Error in the expression)"<<endl;
	outF<<"________________________________"
		<<endl<endl;
}

And where can I find the file: 'mystack.h' ?

And where can I find the file: 'mystack.h' ?

As I said in my original posting. I am practicing with those code from D.S. Malik C++ book this was a complete example on how to implement this program. I guess the book is wrong?

Yeah, but you need that header file to compile your code, sure it isn't listed somewhere in the book?
Otherwise you won't be able to compile this example ...

Yeah, but you need that header file to compile your code, sure it isn't listed somewhere in the book?
Otherwise you won't be able to compile this example ...

Any ideas how would this header file look like?

Nope ...

Any ideas how would this header file look like?

It's in your book according to google

commented: There you've hit the nail right on the head ! +1

I am also having the same problem but unfortunately for me i can't open the book online. This is the error that I am getting

"404. That’s an error.
The requested URL /books?id=HtgSvljvC7IC&pg=PA1126&lpg=PA1126&dq=d.s.+malik+mystack.h&source=bl&ots=SZZDotjQEC&sig=N_3fbvMIonXXfTdSjsWnW2dx7zY&hl=nl&ei=mA3aSaaqIJmv-AbJosjKBQ&sa=X&oi=book_result&ct=result&resnum=1 was not found on this server. That’s all we know.

I don't know what should i do now. Please help

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.