Thread: Simple cout formatting question.

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155

    Simple cout formatting question.

    Hello everyone:

    I have an output formatting question for C++,

    I am writing a program that outputs movie names, the genre, and the categorie


    IT currently looks like cout << movie << "\t\t\t" << cat << "\t\t\t" << genre;

    i've tried also using the setw(X);, but it produced the same problem.

    Display:
    Ice Age ........................ cat ........................... gen
    Saving Private ryan ........................... cat ........................... gen
    Doge Ball .................... cat ........................... gen

    Is there a way to get it to be:
    Title .............................. Categorie................... genre

    Ice age ........................... cat ........................... gen
    Saving Private Ryan ........ cat ........................... gen
    Doge Ball ........................ cat ........................... gen

    this is all dynamic, I just need all the information to be aligned. (names will be changing, categories changing, and genres changin)
    Last edited by guitarist809; 03-27-2006 at 01:15 PM.
    ~guitarist809~

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main() {
       cout << setw(25) << left << "Movie" <<  setw(25) << left 
            << "Category" << "Genre\n" << endl;
       cout << setw(25) << left << "My Movie" <<  setw(25) << left 
            << "Its Category" << "Its Genre" << endl;
       cout << setw(25) << left << "My Longer Movie" <<  setw(25) << left 
            << "Its Longer Category" << "Its Longer Genre" << endl;
       return 0;
    }
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Quote Originally Posted by SlyMaelstrom
    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main() {
       cout << setw(25) << left << "Movie" <<  setw(25) << left 
            << "Category" << "Genre\n" << endl;
       cout << setw(25) << left << "My Movie" <<  setw(25) << left 
            << "Its Category" << "Its Genre" << endl;
       cout << setw(25) << left << "My Longer Movie" <<  setw(25) << left 
            << "Its Longer Category" << "Its Longer Genre" << endl;
       return 0;
    }

    sry, but I don't get it: whats this << left thing?

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    left means left justified

  5. #5

  6. #6
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Thanks for the help guys, it worked really well!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple C++ question. Error in code somewhere.
    By Paracropolis in forum C++ Programming
    Replies: 10
    Last Post: 02-06-2006, 08:59 AM
  2. Simple question - getline()
    By QuietWhistler in forum C++ Programming
    Replies: 3
    Last Post: 01-24-2006, 01:16 PM
  3. Very simple question
    By ZephidsEmbrace in forum C++ Programming
    Replies: 6
    Last Post: 07-27-2003, 02:21 AM
  4. simple question (cout << "two words")
    By bleach in forum C++ Programming
    Replies: 3
    Last Post: 12-29-2001, 12:49 PM
  5. Simple question...
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 08-30-2001, 11:36 AM