Problem with the output

Can someone tell me how to change the code so the input to be like that:

1
2
3
||nick                   || ||9             || ||man  || ||6    || ||5     || ||4          || ||3        || ||2        || ||4                ||
||john                   || ||10            || ||man  || ||6    || ||2     || ||4          || ||3        || ||5        || ||4                ||
||mary                   || ||23            || ||woman|| ||5    || ||6     || ||4          || ||4        || ||2        || ||4                || 


CODE
1
2
3
4
5
6
7
8
9
10
11
12
    for(int j=0;j<i;j++)
    {
        cout<<"||"<<a[j].name<<setw(23-a[j].name.size())<<"||"<<" "<<"||";
        cout<<a[j].dateofbirth<<setw(17-a[j].dateofbirth.size())<<"||"<<" "<<"||";
        cout<<a[j].sex<<setw(7-a[j].sex.size())<<"||"<<" "<<"||";
        cout<<a[j].marks[0]<<setw(6)<<"||"<<" "<<"||";
        cout<<a[j].marks[1]<<setw(7)<<"||"<<" "<<"||";
        cout<<a[j].marks[2]<<setw(12)<<"||"<<" "<<"||";
        cout<<a[j].marks[3]<<setw(10)<<"||"<<" "<<"||";
        cout<<a[j].marks[4]<<setw(10)<<"||"<<" "<<"||";
        cout<<a[j].averagesuccess<<setw(18)<<"||"<<"*"<<endl;
    }
Last edited on
No, I mean that with the code in my previous post my the output is like this

1
2
3
||nick                 || ||9              || ||man  || ||6    || ||5     || ||4          || ||2        || ||3        || ||4                ||
||
john                || ||23             || ||man  || ||5    || ||6     || ||4          || ||3        || ||2        || ||4                ||


but I want to be like this
1
2
||nick                   || ||9             || ||man  || ||6    || ||5     || ||4          || ||3        || ||2        || ||4                ||
||john                   || ||10            || ||man  || ||6    || ||2     || ||4          || ||3        || ||5        || ||4                ||

(the data shouldn't be the same)
Last edited on
Yes, you do:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <iomanip>

int main()
{
  using std::setw;
  std::cout << std::left;
  std::cout << "#" << setw(6) << "hello" << "#" << setw(5) << 7 << "#\n";
  std::cout << "#" << setw(6) << "foo" << "#" << setw(5) << 42 << "#\n";
}

#hello #7    #
#foo   #42   #

Don't you?
Yes but how to make it with for loop in my case
Last edited on
You have:
1
2
3
4
5
6
std::string name = "foo";
int val = 7;
std::cout << std::right; // default

// in loop
std::cout << "#" << name << setw( 6-name.size() ) << "#" << val << setw(5) << "#\n";

I did:
1
2
3
4
5
6
std::string name = "foo";
int val = 7;

std::cout << std::left;
// in loop
std::cout << "#" << setw(6) << name << "#" << setw(5) << val << "#\n";

Topic archived. No new replies allowed.