Okay, so I'm still stumped on an output problem. The problem is, I have list items and one of those column objects has more than one item(the other columns don't for each particular item)

Some reason, when I add another object to the console for printing it ends up like:
Like this image: http://dl.dropboxusercontent.com/u/57922856/dvd.png
I need to make sure that when the previous line has two or more actors, the next line doesn't bunch up in front of the over hanging actors. I'm not sure how to do this, I've tried using endl, but no luck. Any assistance would be great. Here is the full source code: http://justpaste.it/l4ed
Here is my code I need help on:

    {



         //table format
       cout << setw(10) << "\nMovie Title: "
           << setw(10) << "Length:"
           << setw(10) << "Year: "
           << setw(10) << "Actors/Actresses:"
           << setw(10) << "Characters:\n" << endl;

       cout << "------------------------------------------------------------\n";
    for (int i = 0; i < vectorName.size(); i++)
   {
       if(i <1)
       {
       if(mydvd[i].getLength()!=0)
       {
        cout <<endl<<setw(10)<< right << mydvd[i].getTitle()
       <<setw(10)   << mydvd[i].getLength()
           << setw(10) << mydvd[i].getYear();
       }
       else
       {
           cout <<setw(10)<< right << mydvd[i].getTitle();
       }
       }
       else
       {
              if(mydvd[i].getLength()!=0)
       {

        cout <<endl<<setw(10)<< right << mydvd[i].getTitle()
       <<setw(10)   << mydvd[i].getLength()
           << setw(10) << mydvd[i].getYear();
       }
       else
       {
           cout <<setw(10)<< right << mydvd[i].getTitle();
       }
       }


        if(i <1)
           cout<<"\t\t"<<vectorName[i].getName()
            << " "<<vectorCharName[i] << endl;
        else
        {
 cout<<"\t\t\t\t"<<vectorName[i].getName()
            << " "<<vectorCharName[i] << endl;
        }
   }
}

Edited 1 Year Ago by kiail: moved to C++ forum

I suspect that you are over complicating things ?

Take a look at this simplification:

// outPutToBeFixed.cpp //

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>



const char* MENU =
    "Welcome to the DVD Collection Program! \n"
    "What do you want to do?\n\n"
    "1. Add DVD\n"
    "2. Remove DVD\n"
    "3. Update DVD\n"
    "4. Show DVDs\n"
    "0. EXIT\n"
    "Enter a number in range 0..4: ";


// some utilities useful here ... //

template< typename T >
T takeIn( const std::string& msg, const std::string& errmsg = "\nInvalid entry ... try again.\n\n" )
{
    T val;
    while( true )
    {
        std::cout << msg << std::flush;
        if( std::cin >> val && std::cin.get() == '\n' )
            break;
        else
        {
            std::cout << errmsg;
            std::cin.clear(); // clear cin error flags
            std::cin.sync(); // 'flush' cin stream ... //
        }
    }
    return val;
}
// return a (Non-empty) C++ string //
std::string takeInLine( const std::string& msg, bool okEmpty = false )
{
    std::string val;
    while( true )
    {
        std::cout << msg << std::flush;
        getline( std::cin, val );
        if( okEmpty )
            break;
        // else ...
        if( val.size() )
            break;
        // else ...
        std::cout << "\nEmpty line input is NOT valid here ...\n\n";
    }
    return val;
}




class DVD
{
private:
    std::string title;
    double length;
    int year;
public:
    std::string get_title() const { return title; }
    void takeInDVD()
    {
        title = takeInLine( "\nEnter the movie title: " );
        length = takeIn< double >( "Enter the length: " );
        year =  takeIn< int >( "Enter the year released: " );
    }
    void print( std::ostream& os, char endChr = '\n' ) const
    {
        os << std::setw(40) << title << ' '
           << std::setw(10) << length << ' '
           << std::setw(10) << year << endChr;
    }
} ;

// definition for printing DVD objects ... //
std::ostream& operator << ( std::ostream& os, const DVD& d )
{
    d.print( os );
    return os;
}



int showMenuGetChoice()
{
   return takeIn< int > ( MENU ) ;
}

void showTitleLine()
{
    std::cout << std::setw(40) << "NAME" << ' '
              << std::setw(10) << "LENGTH" << ' '
              << std::setw(10) << "YEAR" << '\n'
              << std::string( 62, '-' ) << '\n';
}

void removeFrom( std::vector< DVD >& v )
{
    if( v.size() )
    {
        bool found = false;
        std::string title = takeInLine( "\nTitle to remove: " );
        std::vector< DVD >::iterator it;
        for( it = v.begin(); it != v.end(); ++ it )
        {
            if( it->get_title() == title )
            {
                showTitleLine();
                std::cout << *it << " removing ...\n\n";
                v.erase( it );
                found = true;
                break;
            }
        }
        if( !found )
            std:: cout << '\n' << title << " was NOT found ...\n\n";
    }
    else
        std::cout << "\nNothing to remove ... \n\n";
}




int main()
{
    using namespace std;

    vector< DVD > store;

    bool more = true;
    while( more )
    {
        int ch = showMenuGetChoice();
        switch( ch )
        {
            // Ask the user to enter the details of DVD
            case 1:
            {
                DVD tmp;
                tmp.takeInDVD();
                store.push_back( tmp );
                break;
            }
            case 2: removeFrom( store ); break;
            case 3: cout << "\nUpdate NOT coded yet ...\n\n"; break;
            case 4:
                showTitleLine();
                for( size_t i = 0; i < store.size(); ++ i )
                     cout << store[i];
                cout << '\n';
                break;
            case 0: more = false; break;

            default :
                cout << "\nChoice " << ch << " is NOT implemented here ...\n\n";
           }
       }
}

Edited 1 Year Ago by David W

This article has been dead for over six months. Start a new discussion instead.