免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1841 | 回复: 1
打印 上一主题 下一主题

[C++] 输入输出流重载问题求解 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-04-28 19:43 |只看该作者 |倒序浏览
本帖最后由 ANONYMOUS419 于 2015-04-28 20:03 编辑

#include "Input.h"
#include "Output.h"

int main()
{
        Output out;
        Input in;
        int id;
        float math;
        char str[20];

        out << "请输入学号:";
        in >> id;
        out << "请输入姓名和数学成绩:";
        in >> str >> math;
        out << id << '\t' << str << '\t' << math << endl;
        return 0;
}


#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

class Input
{
public:
        Input & operator>>(int &i)
        {
                scanf("%d", &i);
                return *this;
        }

        Input & operator>>(unsigned int &u)
        {
                scanf("%u", &u);
                return *this;
        }

        Input & operator>>(char &c)
        {
                fflush(stdin);
                c = getchar();
                return *this;
        }

        Input & operator>>(char *str)
        {
                fflush(stdin);
                scanf("%s", str);
                return *this;
        }

        Input & operator >> (float &f)
        {
                scanf("%f", &f);
                return *this;
        }

        Input & operator >> (double &dl)
        {
                scanf("%lf", &dl);
                return *this;
        }
        Input();
        ~Input();
};

#include "Input.h"



Input::Input()
{
}


Input::~Input()
{
}


#pragma once
#define endl "\n"
#include <iostream>

class Output
{
public:
        Output();
        ~Output();
        Output & operator<<(const int i)
        {
                printf("%d", i);
                return *this;
        }

        Output & operator<<(const unsigned int u)
        {
                printf("%u", u);
                return *this;
        }

        Output&operator<<(const char c)
        {
                printf("%c", c);
                return *this;
        }

        Output & operator <<(const char *str)
        {
                printf("%s", str);
                return *this;
        }

        Output & operator <<(const float f)
        {
                printf("%f", f);
                return *this;
        }

        Output & operator <<(const double dl)
        {
                printf("%lf", dl);
                return *this;
        }
};

#include "Output.h"



Output::Output()
{
}


Output::~Output()
{
}





1>------ Build started: Project: HomeWork3, Configuration: Debug Win32 ------
1>  Output.cpp
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(992): error C2988: unrecognizable template declaration/definition
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(992): error C2059: syntax error: 'string'
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(1001): error C2065: '_Elem': undeclared identifier
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(1001): error C2065: '_Traits': undeclared identifier
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(1001): error C2923: 'std::basic_ostream': '_Elem' is not a valid template type argument for parameter '_Elem'
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(1001): error C2923: 'std::basic_ostream': '_Traits' is not a valid template type argument for parameter '_Traits'
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(1002): error C2065: '_Elem': undeclared identifier
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(1002): error C2065: '_Traits': undeclared identifier
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(1002): error C2923: 'std::basic_ostream': '_Elem' is not a valid template type argument for parameter '_Elem'
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(1002): error C2923: 'std::basic_ostream': '_Traits' is not a valid template type argument for parameter '_Traits'
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(1003): error C2143: syntax error: missing ';' before '{'
1>d:\program files (x86)\microsoft visual studio 14.0\vc\include\ostream(1003): error C2447: '{': missing function header (old-style formal list?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

论坛徽章:
0
2 [报告]
发表于 2015-04-28 20:18 |只看该作者
问题已解决,属于重复包含头文件错误
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP