string to char placed into vector

Hey, so I have this project I have to do where I have to convert a txt file into an html file, and when there is a line return I need to insert a <br/> tag. I have never done anything like this and I have looked all over for string to char specific for my problem but none of the methods i have found work, here is my function for inserting the tag... I am relatively new to c++ so clarity would be much appreciated!

string printBr(int argc, string argv)
{
int count = 0;
vector<char>lineBreak;
char ch;
string br = "<br/>";

while(ch != 62);
{

lineBreak.push_back(ch);
count++;
}

string htmlFile = argv;
ofstream outfile(htmlFile);

for (auto x : lineBreak)
{
outfile.put(x);
}
return 0;
}

I am not sure if I am even passing in the correct arguments, I set the argv to a string before I passed it in and then just passed in the string.
Something like this:
1
2
3
4
5
6
std::ifstream text_file( "text file name" ) ;
std::ofstream html_file( "html file name" ) ;

std::string line ;
while( std::getline( text_file, line ) ) // for each line in the text file
    html_file << line << "<br/>" ; // write it out with the newline replaced by "<br/>" 

@JLBorges thanks so much after a little messing around that worked pretty good and to what I thought I needed.

However I just realized I am only supposed to print <br/> tags after a double line return in a row for example

blah blah blah(Line return)
(line return)
blah blah

is supposed to be

blah blah blah<br/>
blah blah

so what i am getting at is, how do I detect line returns efficiently without using some cryptic non-sense coding?
> I am only supposed to print <br/> tags after a double line return in a row

So do a one line look ahead.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
std::ifstream text_file( "text file name" ) ;
std::ofstream html_file( "html file name" ) ;

std::string line ;
std::getline( text_file, line ) ;

std::string next_line ;
while( std::getline( text_file, next_line ) )
{
    if( next_line.empty() ) line += "<br/>" ;
    else
    {
        html_file << line << '\n' ;
        std::swap( line, next_line ) ;
    }
}
html_file << line << '\n' ; // write the last line 

AH! Yes this is what I have been looking for! The method for line look ahead! Thank you so much you're a life saver!
Topic archived. No new replies allowed.