Need tip on editing a text file in C++

This program is supposed to read from an input file and write to an out put file exept the characters #N# should be replaced by the name that the user types in. So far the best I can get it is that it compiles and asks for the users name but all N's in the output file are missing, or it keeps the N's but it replace each instance of # with the users name in the output file. Here's my code for the function that in trying to use for the program.It feels like i'm one tiny step away from success but I just can't put my finger on the problem.
The instructor wants us to use get, put, and puback if needed since that's what we covered in the last chapter.
[code]
void replace_name(ifstream& in_stream, ofstream& out_stream)
02 {
03 using namespace std;
04 char next, name[15], last;
05
06 string replace;
07
08 in_stream.get(next);
09 while(! in_stream.eof())
10 {
11
12 if(next =='#')
13
14 //in_stream.putback(next);
15 in_stream.get(next);
16
17
18 if(next == 'N')
19 {
20 in_stream.get(next);
21 in_stream.putback('N');
22 }
23
24 if(next == '#')
25 {
26 //in_stream.putback(next);
27 cout <<"Enter your name.\n";
28 cin >> name;
29 out_stream << name;
30
31 }
32 else
33
34 out_stream.put( next);
35
36 in_stream.get(next);
37 }
38
39 }
[code/]
Topic archived. No new replies allowed.