using streams

hey guys, i'm new to the site, and i'm trying to figure out how to use ifstreams and ofstreams. i'm in an advanced C++ class which is killing me. i have a project to complete, and need some help, if you guys can direct me in the right direction.

i have to take the information inside a file, format it a certain way, input words where requested, and print it out in the formatted style.

my question, how do i take the information inside the text file i'm opening, make it have only so many characters per line, and output it? i think getline() comes into play, but i don't know how. thanks for any help.
getline() is fine if you have a delimiting character after the "so many characters per line..." bit, but you're better off (because it's easier and we're lazy) formatting your output. You need a loop that counts the number of characters output to the stream, like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

//...

 for(int NoC; NoC < MAXChar; NoC++)
{
      cout.put(Letter[Position_In_Array]);

//or

      OutFile.put(Letter[Position_In_Array]);

}

cout << '\n';

OutFile << '\n';

//...


EDIT: forgot the //'s before my in code notes :S.
Last edited on
so i have this member function written so far, just gotta add more to it to make it do what i said in my first post.

ostream &operator <<(ostream &outStream, const Paragraph &para)
{
// Output number of words in paragraph.
outStream << para.wordCount << endl;

int i;

for (i = 0; i < para.wordCount; i++)
{
if (i > 0)
outStream << ' ';
outStream << para.words[i];
}

return outStream;
}






so i add another loop after the one that's in there, such as:

for(int i; i < len; i++)
{
ostream.put(



and i'm lost after that, sorry. does Letter mean something specific that i'm supposed to know from my already written code, same as Position_In_Array? sorry for dumb questions
anybody have any insight here for me? thanks for any help, guys.
Topic archived. No new replies allowed.