I'M reading "C++ FOR DUMMIES" 4th edition by Stephen Randy Davis and the chapter on arrays as just introduced this line -> cout.width(3); with absolutly no explanation to waht width is. I would like any of you guys to help me wout here but in addition to telling what .width is please also explain to me how I can find this kind of info out on my own. I know that cout is part of std but I don't really understand std. As far as I know it's a library that I've not seen nor do I know where to find it. But knowing that cout is part of std and that width was acccessed through cout, I'M assuming that if I can see into std I could find out for myself what width is.

Test it out and see:

#include <iostream>

using namespace std;

int main()
{
    cout << "'";
    cout << "foo";
    cout << "'\n";

    cout << "'";
    cout.width(10);
    cout << "bar";
    cout << "'\n";

    cout << "'";
    cout.width(10);
    cout.setf(ios::left);
    cout << "baz";
    cout << "'\n";
}

As for where to figure these things out, a combination of a good tutorial book and a good reference book should cover most of the bases. From there it's experimentation and self study.

Thanks. So there's now way to look inside std and cout and width for myself?

So there's now way to look inside std and cout and width for myself?

You can if you want, but unless you're pretty advanced in your C++ knowledge, it'll look like gibberish.

cout is easily referenced by searching at that reference site. cout is from the ostream class, the width property is referenced there.

Thanks all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.