The goal of this program should be to produce a output string such that:
- The output string + spaces in between == the width.
- The strings are not cut off. So, it gives out complete words per line.
This is what I have so far:
int main()
{
int width= 15;
vector<string> line;
line.push_back("Hello");
line.push_back("My");
line.push_back("Name");
line.push_back("Is");
line.push_back("John");
auto s = line.front();
for (auto i = std::size_t {1}; i < line.size(); ++i) s += ' ' + line[i];
for (size_t i = 0; i < s.length(); i+=width+1)
{
s.insert(i,"\n");
}
cout<<s;
}
I wan't to add spaces in between the words evenly so the last string won't get cutoff and it moves to the next line.
This is similar to the question of C++ text full justification but I want to correct my own implementation to the solution of this problem .