Aug 19, 2010 at 2:37am UTC
I want to convert a txt file to htm file.
but when I use ofstream ofs("*.htm").
I find it will automatically combin two lines content to one line in htm file.
why does it happen,and any other way to creat a htm file?
Aug 19, 2010 at 4:28am UTC
good morning
Last edited on Aug 26, 2010 at 5:35am UTC
Aug 19, 2010 at 4:56am UTC
thank you toolbox.below is my code.but I can't get right answer.can you help me to find what is wrong with it?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include <iostream>
#include <string>
#include <fstream>
typedef unsigned int uint;
using namespace std;
void replace()
{
string strline,s;
ifstream ifs("sft004.txt" );
const char * head="<html><head>\n\r<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; CHARSET=UTF-8\"><meta name=\"DESCRIPTION\" CONTENT=\" Serial Monitor HTML file\"><meta name=\"GENERATOR\" CONTENT=\"Serial Monitor\"><meta name=\"COPYRIGHT\" content=\"Micro software\"><meta name=\"Author\" CONTENT=\" Serial Monitor\"><title>t Serial Monitor HTML Export</title></head>" ;
const char * lineodd="<P><FONT face=\"Courier New\" color=\"#0000ff\"><B>" ;
const char * lineeven="<P><FONT face=\"Courier New\" color=\"#ff00ff\"><B>" ;
const char * lineend="</B></P>" ;
const char * body="<body><!--StartFragment --><PRE><CODE>" ;
const char * end="</CODE></PRE></body></html>" ;
char Temp16[4]={0};
char buffer[5]={0};
int strlen,i=0;
s+=*head;
s+=*body;
while (getline(ifs,strline))
{ i++;
if (i%2==0)
s+=*lineeven+strline+*lineend+"\n\r" ;
s+=*lineodd+strline+*lineend+"\n\r" ;
}
s+=*end;
ofstream ofs("sft004.html" );
ofs<<s;
ifs.close();
ofs.close();
}
int main(int argc, char * argv[])
{
replace(); cout << "replace finished" << endl;
cin.get();
return 0;
}
Last edited on Aug 22, 2010 at 5:11am UTC
Aug 23, 2010 at 1:40am UTC
is there some who knows how to do?
Aug 23, 2010 at 2:00am UTC
Well, what are the remaining problems with your code? (other than the formatting looking like a bomb exploded in there)
If the source file contains any quotation marks, you'll have to replace them with "
Aug 23, 2010 at 4:18am UTC
what is the meanning of """you refer to?
the code can be compiled.but the created htm file,is wrong ,there are much ’ <‘ in every line .
and the color is black and white.
Aug 23, 2010 at 5:19am UTC
I hvae substitude all \ " in the code for ". and later substitude \ " for ".
but there is no effect.
Last edited on Aug 23, 2010 at 5:21am UTC
Aug 26, 2010 at 5:36am UTC
good afternoon every one.
Aug 26, 2010 at 9:38am UTC
Have you run this in a debugger? The problem would be obvious as you stepped thru the code.
What does this do?
s+=*head;
How is it different from:
s+=head;
If you fix the indentation, it will be obvious that lineeven
and lineodd
are not being used correctly.
Aug 27, 2010 at 2:25pm UTC
when I get rid of *.it work well.thanks a lot.