ok so i need to ask the user for a file to use for the input, then i need to read the input a line at a time, because i am trying to take postfix expressions from the file and evaluate them then return the result in the user's choice of a text file or just on the screen. The problem i am having now is i dont know how to take the user's input from their file and read a line at a time and put it into a stack im so confused. any help would be great thanks.

/************************************************************************
	Postfix Evaluation Program
	Version 1.0
	
	This is a program that takes a file from the user and evaluates postfix expressions from the file.
		 
	Source File:  postfixEval.cpp

*************************************************************************/
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
//include stack
using namespace std;

int main()
{
	char inFileName[60];
	string outFileName;

	cout << "Enter the name of the input file --> ";
	cin >> inFileName;
	cout << endl << endl;

	ifstream postfixFile;  // Input filestream variable
	
	// Attempt to open the file
	postfixFile.open(inFileName);
	// Check to make sure it opened
	if( postfixFile.fail() )
	{
		cout << "Error opening input file." << endl;
		exit(EXIT_FAILURE);
	}

	while( !postfixFile.eof() )
	{
		//have user input placed into stack here!!
	}
			
	cout << "The file contained " << numChars << " characters." << endl;
	
	// Close the file -- necessary if the file is to be reread
	myIn.close();
	
	cout << "Enter the name of the output file --> ";
	cin >> outFileName;
	cout << endl << endl;
	
	ofstream resultFile; // Output filestram variable
	// Attempt to open the file
	resultFile.open(outFileName.c_str());  // Filename must be a cstring
	// Check to make sure it opened
	if( resultFile.fail() )
	{
		cout << "Error opening output file." << endl;
		exit(EXIT_FAILURE);
	}

	// Write some stuff to the file
	myOut << "This is written to the file." << endl;
	
	// Be sure to close the file -- otherwise it may not be created
	myOut.close();
	
	return EXIT_SUCCESS;
}

Where's myIn and myOut declared?

its not it myin should be postfixFile and myout should be resultFile

Use getline.. myIn.getline(expression,SIZE,delimiter). SIZE is no of characters, delimiter denotes end of input default '\n'

Edited 4 Years Ago by v3ga: n/a

This article has been dead for over six months. Start a new discussion instead.