Chinaunix

标题: 输入输出流重载问题求解 [打印本页]

作者: ANONYMOUS419    时间: 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 ==========

作者: ANONYMOUS419    时间: 2015-04-28 20:18
问题已解决,属于重复包含头文件错误




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2