Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output to RTF, Format is being deleted by C++

Status
Not open for further replies.

muthuivs

Technical User
Jan 30, 2006
36
CA
I am now trying to print the output to a RTF template that will defintely work since I have my formatting saved in the template but once my program writes to it , the formatting in the RTF is all deleted. Any Idea how to get around that? It doesn't even save the page setup for printing.


MuthuIVS
 
Hard to say without seeing some code.

If you're reading from a template and mixing in your content, then you need to output the results to a different file. There is no 'insert' function like a text editor.

--
 
But how do I transfer the data to my template file to print? As for code: Here is the code where I call to opent the rtf file, then attempt to write to it. It writes to the file but my formatting in the file is gone.

ofstream fout("c:/Program Files/MyRenamer/LabelTemplate.rtf");

for(int i=101; i<=180; i++)
{

if (counter == 1)
{
str1.str("");
str1<<clientcode<<loccode<<datecode<<initialcode<<agentcode<<i<<left;
fout<<str1.str().c_str()<<"\t\t";
counter++;
}
else if (counter == 2 || counter == 3)
{
str1.str("");
str1<<clientcode<<loccode<<datecode<<initialcode<<agentcode<<i<<left;
fout<<str1.str().c_str()<<"\t\t";
counter++;
}
else if (counter == 4)
{
str1.str("");
str1<<clientcode<<loccode<<datecode<<initialcode<<agentcode<<i<<left;
fout<<str1.str().c_str()<<"\t";
counter = 1;
}


}
 
Well you have to do something like

Code:
ifstream fin("c:/Program Files/MyRenamer/LabelTemplate.rtf");
ofstream fout("c:/Program Files/MyRenamer/result.rtf");

Assuming that you want to end up with something like
<template><data><template>

- You read from fin and write to fout until you get to the point you want to insert your data.
- Then write your data, as you do at present.
- Then read from fin and write to fout the remainder of the template.

--
 


How do you read a template though? Aren't templates page margins, tab distances and so on. How do you read stuff like that and write it to another file?
 
One character at a time.
At it's most basic level, files are just sequences of bytes.


--
 
Its strting to work, this is what I am doing, I am first trying to just read the template and print it to another file:

The only question now is do I need to clear the char variable everytime I read a charachter? If so would char buffer = ' ' , work?

Code


ifstream fin("c:/Program Files/INPUT.rtf");
ofstream fout("c:/Program Files/OUTPUT.rtf");
while(!fin.eof())
{
//buffer is delared as char
fin>>buffer;
tout<<counter<<": "<<buffer;
counter++;
fout<<buffer;

}
fin.close();
fout.close();
 
Thanks Salem...it works now. I thought it was the same as writing to a text file!! I guess not. have a great weekend.


MuthuIVS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top