C++ IO流作业

流:若干字节数据从一端到达另一端我们叫做流

流类体系:流对象,和流运算符>>  <<

输入输出流

ostream类:cout,cerr,clog,istream类 cin

#include
using namespace std;
void testostream()  
{

    cout << "标准输出" << endl;    //可以重定向
    cerr << "标准出错" << endl;    //不能重定向
    clog << "标准错误输出" << endl;//这里可以重定向为文件


}

int main() 
{



    return 0;
}

很多人对重定向不太了解 ,文件重定向就是程序的输入或者输出都可以由文件来完成

从文件输入到程序中,或者程序中到文件内

#include
#include
using namespace std;
void testostream()  
{

    cout << "标准输出" << endl;    //可以重定向
    cerr << "标准出错" << endl;    //不能重定向
    clog << "标准错误输出" << endl;//这里可以重定向为文件


}

int main() 
{
    int temp, temp2;
    freopen("狐狸.txt","r",stdin);//重定向输入当程序运行起来 到该文件中读取数据
    scanf("%d%d",&temp,&temp2);//将按照格式格式控制字符拿取数据
    cout << temp << temp2 << endl;//我们打印测试
    freopen("狐狸2.txt", "w", stdout);//定向为输出
    printf("%d", temp+ temp2);//这里的打印将输出到文件中
    return 0;
}

关于输出字符类的处理

一种是调用成员函数的,一种是正常调用

#include
#include
using namespace std;
void testostream()  
{

    cout << "标准输出" << endl;    //可以重定向
    cerr << "标准出错" << endl;    //不能重定向
    clog << "标准错误输出" << endl;//可以重定向
    //字符类的处理
    cout.put('A');//调用成员函数
    cout << 'A

你可能感兴趣的:(c++,visual,studio,c语言)