passing in ifstream and getting a word, without use of vector

Hi everyone,

I have to create a function which passes in an ifstream& output and an ofstream. The ifstream is a file, which I need to take each word and translate. My issue is how do I deal with spaces and is it preferable that I do a output.get(ch) rather than an output.getline(string,index).

I then need to call the function recursively to do the encode the whole file, so I need to putback all of the string after this word.

This is the function header:
void translateStream(ifstream& inputStream, ofstream& outputStream)

Note, I cannot use vector, and the only includes I have available to me are
#include<iostream>
#include<cctype>
#include<fstream>
#include<cstring>


Thanks

Ruby
Have partially solved it using this:



void translateStream(ifstream& inputStream, ostream& outputStream){

char word[64], translated[70], ch;
translated[0]='\0';
word[0]='\0';

while(!inputStream.eof()){
inputStream>> word;
translateWord(word, translated);
// if(inputStream>> endl){
// outputStream<< endl;
// }
outputStream<< translated;
outputStream<< " ";
translateStream(inputStream,outputStream);
}
return;
}


HOWEVER this does not deal with the endl my txt file has which I bring in. Any suggestions?
If you need to honor existing newlines in the input file then you probably want to grab input "lines" and tokenize them so that you can reproduce the format on output. Something like:


1
2
3
4
5
char wordLine[1025] = {0};
while(inputStream.getline(wordLine,1024))
{
   // tokenize out words, translate, output, output endl
}
Is there no other way other than doing a getline? As I believe I would have to add a new header for Tokenize, which is something I cannot do (restrictions for my exam on what can and can't be done!)
tokenize is not a standard function

it's one you've got to write using the standard string functions (in <string>)

Andy
Topic archived. No new replies allowed.