Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algorithms and flowcharts (Yet another C++ assignment).
#12
Siiigh. Okay so this thing is due tomorrow and I've made hardly any progress. I thought I would be okay after trying to figure out an algorithm (and I don't have that completely down), but once I went into the actual program and looked at the assignment instructions, I noticed that I still have no idea what I'm doing. Sad

First step, I don't know how on Earth I need to define this function.

Code:
void GetWord(istream & inF, int & linepos, int & wordpos, string & word);

void GetWord(istream & inF, int & linepos, int & wordpos, string & word)
{
    while(
}

That's as far as I got. I know I need to get it to read the indicator, the position and the word. Also note that I can't change the functions' parameters, they're part of the assignment. The functions are the only defined things in there, though.

I wasn't sure how to do that (though the pseudocode is helping) so I tried to see if I can print everything out first, both to the terminal and to the output file. But I can't even test it, because I'm getting errors in this section. All I want it to do is read the input file that gets entered...

Code:
string inFileName;                //Name of the string value that holds the input file name.
string outFileName;                //Name of the string value that holds the output file name.
ifstream inF;                    //Declared input file.
ofstream outF;                    //Declared output file.

//-| ----------------------------------------------------------------------
//-| 1. Read names of input and output files.
//-| ----------------------------------------------------------------------

cout << "Enter Name of Input File: ";        //Prompts for input filename.
cin >> inFileName.c_str();            //Enter input filename. I MAY HAVE NOT USED THIS PROPERLY.

//-| ----------------------------------------------------------------------
//-| 2. Open input file. If this fails, terminate the program.
//-| ----------------------------------------------------------------------
  
inF.open(inFileName);                //Opens input file.

if(inF.fail())                    //Checks if the file was opened successfully.
{
    return 1;                //Terminates program if file is not found.
}

[MENTION=4093]SaptaZapta[/MENTION]; Do you recall the error I got when I tried to do this exact same thing (open an entered filename) in the last assignment? Apparently I need to use .c_str() to get it to work while keeping inFileName as a string value. But apparently I don't know how to use it... since it's not working when I use it here.

And for the record, yes, I'm very picky about my programming format. GOTTA LOOK PRETTY.

EDIT: Let's not pull another all-nighter for this. I'll come back to this thread in the morning. Sad
Reply


Messages In This Thread
Algorithms and flowcharts (Yet another C++ assignment). - by MariettaRC - 2013-09-25, 02:10 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)