bcb中如何使用cout和cin来控制输入输出啊?
那位仁兄能给在下指点一下? 问题点数:20、回复次数:9Top
1 楼ynlzl(小百姓)回复于 2005-06-30 22:10:33 得分 0
我也不会,帮顶一顶。Top
2 楼songhtao(三十年孤独)回复于 2005-07-01 08:37:03 得分 0
#include<iostream>
#include<iomanip>
void main ( )
{
using namespace std;
int i;
float f;
// read an integer and a float from stdin
cin >> i >> f;
// output the integer and goes at the line
cout << i << endl;
// output the float and goes at the line
cout << f << endl;
// output i in hexa
cout << hex << i << endl;
// output i in octal and then in decimal
cout << oct << i << dec << i << endl;
// output i preceded by its sign
cout << showpos << i << endl;
// output i in hexa
cout << setbase(16) << i << endl;
// output i in dec and pad to the left with character
// @ until a width of 20
// if you input 45 it outputs 45@@@@@@@@@@@@@@@@@@
cout << setfill('@') << setw(20) << left << dec << i;
cout << endl;
// output the same result as the code just above
// but uses member functions rather than manipulators
cout.fill('@');
cout.width(20);
cout.setf(ios_base::left, ios_base::adjustfield);
cout.setf(ios_base::dec, ios_base::basefield);
cout << i << endl;
// outputs f in scientific notation with
// a precision of 10 digits
cout << scientific << setprecision(10) << f << endl;
// change the precision to 6 digits
// equivalents to cout << setprecision(6);
cout.precision(6);
// output f and goes back to fixed notation
cout << f << fixed << endl;
}
//
// cout example #2
//
#include <iostream>
void main ( )
{
using namespace std;
char p[50];
cin.getline(p,50);
cout << p;
}
//
// cout example #3
//
#include <iostream>
#include <fstream>
void main ( )
{
using namespace std;
// open the file "file_name.txt"
// for reading
ifstream in("file_name.txt");
// output the all file to stdout
if ( in )
cout << in.rdbuf();
else
{
cout << "Error while opening the file";
cout << endl;
}
}Top
3 楼Maconel(Maconel)回复于 2005-07-01 08:49:11 得分 5
cout 和 cin 是在控制台程序中用的。Top
4 楼smarthui(光君)回复于 2005-07-01 09:27:49 得分 0
跟纯C++里一样吧,应该不会有区别。Top
5 楼wangzg1()回复于 2005-07-01 09:33:38 得分 5
只能用于console吧Top
6 楼XBox360(菜)(鸟)回复于 2005-07-01 09:46:51 得分 0
我好象只见过用于console才这样
其他不知道,请大虾们指点!Top
7 楼huabihan(心灵waiting)回复于 2005-07-01 11:48:24 得分 5
应该是只能用在控制台的.Top
8 楼sunliwen780502(孙立文)回复于 2005-07-01 16:10:33 得分 5
只能用在Console程序中。Top
9 楼kkklmn(小虫)回复于 2005-07-03 21:07:19 得分 0
那什么叫做控制台程序呢?我是菜鸟:)Top




