Thread: setw(), setiosflags(), etc

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    45

    setw(), setiosflags(), etc

    can anybody tell me how these work. my book is kinda confusing..and when i do what i think will work ,it just comes out whever it wants to. this is what i have and it doesn't line up like i want it to...in 3 columns.

    Code:
    #include<iostream.h>
    #include<iomanip.h>
    
    int main()
    {
    	int x;
    	int y;
    	int stockNum[2];
    	int quantity[2];
    	double Price[2];
    
    	for(x=1;x<3;++x)
    	{
    		cout<<"Enter Stock Number: ";
    		cin>>stockNum[x];
    		cout<<"Quantity: ";
    		cin>>quantity[x];
    		cout<<"Price: ";
    		cin>>Price[x];
    	}
    
    	cout<<"You Entered: "<<endl<<endl;
    
    	cout<<setiosflags(ios::left)<<"Stock Number";
    	cout<<setiosflags(ios::right)<<setw(35)<<"Quantity"
    	cout<<setw(40)<<setiosflags(ios::right)<<"Price"<<endl;
    	for(y=1;y<3;++y)
    		cout<<resetiosflags(ios::left)<<stockNum[y]<<setiosflags(ios::right)<<setw(25)<<quantity[y]<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint | ios::right)<<Price[y]<<endl;
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. setw question
    By dhrodrigues in forum C++ Programming
    Replies: 9
    Last Post: 07-14-2004, 08:34 AM
  2. setw newb help
    By smcan in forum C++ Programming
    Replies: 3
    Last Post: 10-16-2003, 07:27 PM
  3. setw
    By RedRuM5746 in forum C++ Programming
    Replies: 3
    Last Post: 11-06-2002, 08:02 PM
  4. Problem with setw
    By PJYelton in forum C++ Programming
    Replies: 3
    Last Post: 10-15-2002, 02:56 PM
  5. setw() and named constants
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 02-11-2002, 02:22 PM