You can use <iomanip.h> =>
登录 | 论坛导航 -> 华新鲜事 -> 求学狮城 | 本帖共有 3 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:魅力十足 (等级:2 - 初出茅庐,发帖:15) 发表:2003-03-12 21:21:20  楼主  关注此帖
请问:关于c++左端对齐...#include ...... cout (more...)
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!
Put your OWN COOL signature here!
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:魅力十足 (等级:2 - 初出茅庐,发帖:15) 发表:2003-03-13 00:31:03  2楼
再问:关于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!
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:魅力十足 (等级:2 - 初出茅庐,发帖:15) 发表:2003-03-16 01:16:17  3楼
You can try this =>A very intuitive way to do it: #include #include using std::string; main(void) { string text( "Hello! I want it that way" ); int number=0; cout (more...)
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?
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
论坛导航 -> 华新鲜事 -> 求学狮城 | 返回上一页 | 本主题共有 3 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码