登录 | 首页 -> 华新鲜事 -> 求学狮城 | 切换到:传统版 / sForum | 树形列表
请问:关于c++左端对齐...
<<始页  [1]  末页>> 

请问:关于c++左端对齐...#include <iomanip>
......
cout<<setw(8)<<"hello"...

.....

hello总是在8字符的最右边,怎么左端对齐?

3x
[notice (3-12 21:04, Long long ago)] [ 传统版 | sForum ][登录后回复]1楼

You can use <iomanip.h> =>For formatted input/output, the file <iomanip.h> is very useful,

and we can say it is the key factor.


cout << setiosflags(ios::left); //to left-adjustify the output.


cout << setw(8) << "Hello" << endl;


The problem is solved. :) easy?


Do make yourself familiar with <iomanip.h>


Wish you a good day!
[魅力十足 (3-12 21:21, Long long ago)] [ 传统版 | sForum ][登录后回复]2楼

===>#include <iomanip>
......
cout<<setiosflags(ios::left)
<<setw(8)<<"hello"...

.....

[hobo (3-12 21:22, Long long ago)] [ 传统版 | sForum ][登录后回复]3楼

(引用 hobo:===>#include ...... cout...)被下面抢先了.... :-)[hobo (3-12 21:23, Long long ago)] [ 传统版 | sForum ][登录后回复]4楼

再问:关于c++的问题#include <iomanip>
....
string s("hello");
...

请问string 如何set width?(setw是不行的)
[notice (3-12 22:27, Long long ago)] [ 传统版 | sForum ][登录后回复]5楼

(引用 notice:再问:关于c++的问题#include .... string s("hello"); ... 请问string 如何set width?(setw是不行的))You can try this =>A very intuitive way to do it:

#include<iostream.h>
#include<string>
using std::string;
main(void)
{
string text( "Hello! I want it that way" );
int number=0;

cout << "Please enter the number of characters you want to display"
<< endl;
cout << flush;
cin >> number;

for(int i=0;i<number;i++)
cout<<text[i];
cout << endl;

return 0;
}// end of the source code.


Right now, I don't know any build-in functions to do that. :)

Any way, Good good study, day day up!!!

Cheers!
[魅力十足 (3-13 0:31, Long long ago)] [ 传统版 | sForum ][登录后回复]6楼

(引用 魅力十足:You can try this =>A very intuitive way to do it: #include #include using std::string; main(void) { string text( "Hello! I wan...)Ha ha ha.... A simple version =>#include<iostream.h>

main(void)
{
char str="Happy birthday to you!";

cout.write(str, 15);

return 0;
}

Unformatted output:

the syntax is: cout.write(char *, int n);

Any easy way?
[魅力十足 (3-16 1:16, Long long ago)] [ 传统版 | sForum ][登录后回复]7楼


<<始页  [1]  末页>> 
登录 | 首页 -> 华新鲜事 -> 求学狮城 | [刷新本页] | 切换到:传统版 / sForum