3 Replies - 1067 Views - Last Post: 23 March 2010 - 09:23 AM Rate Topic: -----

#1 maddy123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-March 10

Prefix evaluation program fatal error

Posted 23 March 2010 - 08:48 AM

hi. please help me with this ..i'm trying to develop the code for prefix evaluation using STL []it give me error(fatal error)..the code is give bellow
// PrefixExpressionEvaluator.cpp : main project file.

#include "stdafx.h"
#include <stack>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace std;

template <class T>
bool from_string(T& t, 
                 const std::string& s, 
                 std::ios_base& (*f)(std::ios_base&))
{
  std::istringstream iss(s);
  return !(iss >> f >> t).fail();
}

int main(array<System::String ^> ^args)
{
ifstream myfile;
ofstream outfile;
myfile.open("Prefix.txt", ios::in); //opening streams
outfile.open("output.txt", ios::out);
while (!myfile.eof()) //while not end of input file
{
int value, value1, value2;
char token;
stack<int> s;
stack<int> aux;
stack<char> operators;
stack<char> flags;
std::string line;
std::string outputLine;
std::string intvalue;
getline(myfile, line); //read the next line of file and store into ‘line’
if ( line.length() == 0 )
	continue;
 for(int i=0 ; i < line.length() ; i++)
 {		
  char token = line.operator [](i);
  if ( token.Equals(' ')) 
  {
	  if ( intvalue.length() > 0 )
	  {
		  int val = 0;
		  from_string<int>(val,intvalue,std::dec);
		  s.push(val);
		  intvalue.clear();
	  }
	  continue;
  }
  if(isdigit(token))
  {
	  intvalue += token;
	  if ( i == (line.length() - 1) )
	  {
		  int val = 0;
		  from_string<int>(val,intvalue,std::dec);
		  s.push(val);
		  intvalue.clear();
	  }
  }
  else
  {
	 operators.push(token);
  }
 
 }
 while ( !s.empty() )
 {
	value = s.top();
	s.pop();
	aux.push(value);	
 }
 value = 0;
 while ( !operators.empty() )
 {
	token = operators.top();
	operators.pop();
	value2 = aux.top();
	aux.pop();
	value1 = aux.top();
	aux.pop();
	switch(token)
	{
	  case '+': value = value1 + value2;
	  break;
	  case '-': value = value1 - value2;
	  break;
	  case '*': value = value1 * value2;
	  break;
	  case 'D': value = value1/value2;
	  break;
	  case 'M': value = value1%value2;
	}
	aux.push(value);
 }
 const char* str = (const char*)(Marshal::StringToHGlobalAnsi( String::Format("Prefix Value: {0} \n",value))).ToPointer();
 outfile.write(str,String::Format("Prefix Value: {0} \n",value)->Length);
 Console::WriteLine(String::Format("Prefix Value is : {0} ",value));
}
myfile.close();
outfile.close();
Console::ReadLine();
return 0;
}


pls help me out with this one....
thanks in advance....

Is This A Good Question/Topic? 0
  • +

Replies To: Prefix evaluation program fatal error

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: Prefix evaluation program fatal error

Posted 23 March 2010 - 08:49 AM

ARRRRGGGGHHHHH!

WHAT IS THE FATAL ERROR??? DO YOU EXPECT US TO BE PSYCHIC????
Was This Post Helpful? 0
  • +
  • -

#3 maddy123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-March 10

Re: Prefix evaluation program fatal error

Posted 23 March 2010 - 09:17 AM

View PostJackOfAllTrades, on 23 March 2010 - 07:49 AM, said:

ARRRRGGGGHHHHH!

WHAT IS THE FATAL ERROR??? DO YOU EXPECT US TO BE PSYCHIC????



it gives this error
fatal error C1093: API call 'ImportFile' failed '0x80070003' : ErrorMessage: The system cannot find the path specified
Was This Post Helpful? 0
  • +
  • -

#4 Guest_Guest*


Reputation:

Re: Prefix evaluation program fatal error

Posted 23 March 2010 - 09:23 AM

Entering your error in Google found this: http://barny21.blogs...importfile.html
Was This Post Helpful? 1

Page 1 of 1