Hi, all
How do you print a text to the right side of a console line? In other words how do you print right aligned text in a console? I do not want to use Windows console function because this process should also work in ms-dos.
Hi, all
How do you print a text to the right side of a console line? In other words how do you print right aligned text in a console? I do not want to use Windows console function because this process should also work in ms-dos.
We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.
right is the manipulator for right justification. You may also need setw(). Have a play around. I dont use iostreams much.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
but how does this work when the screen size is changed, wich can be done in XP/2000?
And when I try to compile this with VC++ it says:
: error C2065: 'setw' : undeclared identifier
What besides iostream.h do I need to include?
We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.
setw is in iomanip
You need iomanip.h
Also, just assume the screen is 80x25. Otherwise you will have to call a bunch of Win32 console API's.
Search this message board and look at the FAQ too.
gg
ok thanks
We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.
I think I meant 80x50...whatever a fullscreen console is.
gg
...80x25
but printing anything on the 25th line will scroll the screen - it appears.
Excuse me, while I water my money tree.
Code:#include <iostream> #include <iomanip> using namespace std; int main() { cout << "This is right alligned: *" << setiosflags(ios::right) << setw(10) << 123 << "*" << endl; return 0; }
how about
Code:cout.setf(ios::right);
nextus, the samurai warrior
whats wrong with just right?
cout<<setw(40)<<right<<"This text is right justified"<<endl;
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
IT DOESN'T WORK!
Ok, forgive me. I'm a little flustered. I've been battling with this unconventional Borland C++ for a few days now and it's really getting on my nerves.
The left or right parameters don't seem to work for me in Borland C++ 5.02. What nextus had suggested worked BEAUTIFULLY.
Clearly there are different standards of C++ out there and I just happen to have the one that is the odd one out!! Just my luck. Do you know that I found myself going BACK to C's gets function to capture a line of text (with spaces) from the input stream because getline is BUG ridden?
To me, the only thing C++ has over C is:
1) Classes
2) Inheritance
3) Overloading Operators
4) Polymorphism
5) The String class/data type (finally! ..... char * is a pain in the...)
...and that's just about it. Aside from that, give me C anyday. If Borland's implementation of C++ is making me unjustly hate C++ then that just goes to show you it is like a standard that has yet to settle down.
People tell me about the fix for certain modules and that they are in certain header files. When I check those header files, I realise the lines of code they refer to, don't even exist. I further realise that those lines of code, or even the definition for certain classes don't even exist in the header files they specify. They exist somewhere else!
I ask a buddy for help, only to realise that the C++ he uses is wired for Hand Held application programming!
Just how many standards of C++ are there out there with their third party modifications? I miss the days in the C forum when Prelude could tell me type this line of code and GOD knows it WILL work.
Why? Because C has settled down and most everyone is using the same files, the same code, the same compiler/engine.
With C++, people say type this line of code and when you try it you get some far out message that says:
I don't know about you guys, but I've had it with trying to get C++ to work. I'm going back to the tried and true functions in C that I know will work, like Gets instead of Getline and Printf instead of cout etc. etc. ..........LEFT is NOT a member of the STD class
I'll play with the classes and inheritance and polymorphism when I need to. But as far as I'm concerned, both languages are one in the same.
Peace.
Excuse me, while I water my money tree.
There are many ways to do what you asked. All three ways suggested work. There is also only ONE standard. Third parties may add to it if they want, but its unlikely they'll substract.
**** I suggest getting a newer compiler. ****
left is not part of the std class, it's part of the std namespace (and the ios namespace).
Classes is a reason why C++ is indefinatly better than C. C++ is a superset of C.
And how about the vector, map, queue, stack, + classes? C++'s standard has so much more than what you studied so far.
I cannot deny the usefulness of C++. Indeed I have studied a relatively limited portion of the superset that is C++ - a fundamental portion in any case.
I have already taken the suggestion of many and am currently in the process of changing my compiler. I'm moving to Borland C Builer 6 in hopes that much of my headaches will disappear.
Failing which, I may just whip out my Visual Studio Suite....
....again.
Excuse me, while I water my money tree.