I need help with my program. I need to create a file formatter where i read from a file, create a new file and format the contents from the original file to 60 characters per line. if i come across ".ll 44" in the file, i must format from to 44 characters per line. if i come across ".llN" i must create a new paragraph. The only issue im having is figuring out how to read each string element in my vecter charactor by character, and if i come across a ".ll 55", how do i cast from the 55 from string to int so i can reset the line length
my code so far:
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <fstream>
# include <ctime>
# include <cstring>
# include <vector>
usingnamespace std;
int main(int argc, constchar * argv[])
{
int count =0;
ifstream file;
ofstream answer;
string paragraph = ".llN";
file.open("test.txt");
answer.open("answer.txt");
vector<string> myvec;
// string arr[100];
int length =20;
string temp = "";
while(!file.eof())
{
file>>temp;
myvec.push_back(temp);
myvec.push_back(" ");
}
for(unsignedint i; i < myvec.size(); i++)
{
count++;
if(count == length)
{
if(myvec[i+1] == " ")
{
myvec[i]= "\n";
count = 0;
//answer<<"\n";
}
else
{
count = 0;
answer<<"\n";
}
}
elseif(myvec[i] == ".llN")
{
answer<< "\n";
myvec[i+1] = "";
}
elseif(myvec[i] == ".ll")
{
myvec[i] = "";
//length = myvec[i+1];
myvec.at(i);
}
else
{
answer<<myvec[i];
}
}
}
My test file:
Now this is the story all about how My life got flipped, turned upside down And I'd like to take a minute just sit right there I'll tell you how I became the prince of a town called Bel Air In west Philadelphia born and raised On the playground where I spent most of my days Chilling .llN 65 out, maxing, relaxing all cool And all shooting some b-ball outside of the school When a couple of guys who were up to no good Started making trouble in my neighborhood I got in one little fight and my mom got scared And said you're moving with your auntie and uncle in Bel Air Read more: Will Smith - The Fresh Prince Of Bel Air Lyrics | MetroLyrics
After my code runs:
Now this is the story all about how My life
got flipped, turned upside down And I'd like to take
a minute just sit right there I'll tell you how
I became the prince of a town called Bel Air
In west Philadelphia born and raised On the playground where
I spent most of my days Chilling
65 out,
maxing, relaxing all cool And all shooting some b-ball outside
of the school When a couple of guys who were
up to no good Started making trouble in my neighborhood
I got in one little fight and my mom got
scared And said you're moving with your auntie and uncle
in Bel Air Read more: Will Smith - The Fresh
Prince Of Bel Air Lyrics | MetroLyrics MetroLyrics