I am trying to create a program using formatted output to the screen, two columns 15 characters wide, with the output being strings. If the string is longer than 15 characters I want to truncate it to fit in the column. So far this is what I have:
This works, but I was wondering if there was a way to do it without the use of tempstring. Maybe a string member function?
using namespace std;
string mystring1="This is a string";
string mystring2="This is another string";
cout<<tempstring.assign(mystring1, 0, 15)<<" ";
cout<<tempstring.assign(mystring2, 0, 15)<<"\n";