|
-
Jul 29th, 2002, 12:39 PM
#1
Thread Starter
Addicted Member
formatting output *resolved*
how do you get text to be printed in a specific column, like 20 spaces from the left? THat is, without just printing blank space like this " ", though, because I might have text before it that would affect the aligned text~!
Code:
some text aligned at 20
more aligned at 20
',cr.pgp.l,eo and again
random stuff but this is still aligned at 20!
thanks in advance
Last edited by DarkMoose; Jul 31st, 2002 at 11:13 AM.
To understand recursion, one must first understand the concept of recursion.
-
Jul 29th, 2002, 01:05 PM
#2
Monday Morning Lunatic
Code:
#include <iostream>
#include <iomanip>
// ...
std::cout << std::setwidth(20) << "something" << "This is aligned" << std::endl;
That should work
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 29th, 2002, 01:50 PM
#3
Stuck in the 80s
Actually, it's setw(), not setwidth()
-
Jul 29th, 2002, 01:53 PM
#4
Stuck in the 80s
and that also won't entirely work:
This is what I did:
Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
string str1 = "fish";
cout << str1 << setw(40 - str1.length()) << "this is at 40" << endl;
str1 = "fungus";
cout << str1 << setw(40 - str1.length()) << "this is at 40" << endl;
return 0;
}
-
Jul 29th, 2002, 05:41 PM
#5
Stuck in the 80s
if you need an explaination or anything, let me know. It's pretty much self-explainitory.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|