UGN Security Forums
My ProfileMember DirectoryLogin
Search our ForumsView our FAQView our Site Rules
View our CalendarView our Active TopicsGo to our Main Page

UGN Security Store
 

Network Sites UGN Security, The GoNix Initiative, Elite Web Gamers, Back of the Web, EveryDay Helper, VNC Web Design & Development
January
Su M Tu W Th F Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Sponsored Links
Latest Postings
【煦色韶华问佛】
by lmnopq127978
Today at 03:38 AM
【听,梦里雪落的声音】
by lmnopq127978
Today at 03:37 AM
那天,她留下了眼泪
by lmnopq127978
Yesterday at 04:09 AM
繁荣如锦,似梦似幻
by lmnopq127978
Yesterday at 04:08 AM
爱笑
by lmnopq127978
Yesterday at 04:07 AM
江南小镇
by lmnopq127978
Yesterday at 04:07 AM
癫痫病能够吃油炸食品吗
by lmnopq127978
Yesterday at 01:16 AM
癫痫病的饮食应当留神哪些
by lmnopq127978
01/25/15 07:09 PM
Latest Reviews
Topic Options
Rate This Topic
#17496 - 10/24/04 04:28 AM A pretty easy c++ question regarding program output
Rapture Offline
Member

Registered: 04/23/02
Posts: 212
Loc: Redwood
Hey all, I'm almost finished with a little rpn calculator program but I have one question. One of the requirements is that it outputs at the end of file


right now I have it set up to quit on "q" and print on "p"

how would I make it so that it prints out at the end of the file?

sample of my main()

Code:
using namespace std;

#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>

#include "dstack.h"
#include "integer.h"

int main()
{
    Stack values;
    
    string command;
    
    while (cin >> command && command != "q")
    {
        if (isdigit(command[0]))
        {
            int input = atoi(command.c_str());
            Integer wrapper(input);
            values.push(wrapper);
        }
        else
        {
            Integer x;
            Integer y;
            
            switch (command[0])
            {
            case '+':
                values.pop(x);
                values.pop(y);
                values.push(Integer(y.intValue() + x.intValue()));
                break;
            
            case '-':
                values.pop(x);
                values.pop(y);
                values.push(Integer(y.intValue() - x.intValue()));
                break;
            
            case '*':
                values.pop(x);
                values.pop(y);
                values.push(Integer(y.intValue() * x.intValue()));
                break;
            
            case '/':
                values.pop(x);
                values.pop(y);
                values.push(Integer(y.intValue() /  x.intValue()));
                break;
            
            case 'p':
                values.pop(x);
                x.writeToFile(cout);
                values.push(x);
                cout << endl;
            }
        }
    }
}
any help would be much appreciated. I'm just really confused

Top
Sponsored Links
      
#17497 - 10/27/04 10:00 AM Re: A pretty easy c++ question regarding program output
zenon Offline
Junior Member

Registered: 03/31/02
Posts: 93
Loc: Sweden
Okay, so..
I supose that this Integer class of yours handles output streams?

x.writeToFile(cout);

It would help if you could post at least the member writeToFile(iostream) so that we can examine it.

Otherwise, I would go using the
library and write an member like

writeToFile(char *name)

maybe something..

bool Integer::writeToFile(char *name){
ofstream out(name);
if(!out){
return false;
}else{
//out to the file
out.close();
return true;
}
}

just a fast doodle..
_________________________
- "It's not my code that's useless
it's you loosers being unable to
apprecitate it because of your
lack of skills!"
/zenon - C++ master Apprentice

Top

Featured Member
Registered: 03/02/02
Posts: 136
Forum Stats
2153 Members
46 Forums
36644 Topics
71814 Posts

Max Online: 1567 @ 04/25/10 05:20 AM
Top Posters
UGN Security 29797
Gremelin 7193
§intå× 3255
SilentRage 1273
Ice 1146
pergesu 1136
Infinite 1041
jonconley 955
Girlie 908
unreal 860
Newest Members
claralobo, cdefgh368568, HushHush, golqm, Tim050
2152 Registered Users
Who's Online
1 registered (lmnopq127978), 298 Guests and 241 Spiders online.
Key: Admin, Global Mod, Mod
Latest News


Donate
  Get Firefox!
Get FireFox!