所以我正在组建一个程序来打印不同数据类型的二进制表示,当我编译时,我得到了这些错误


C:\ Users \ Bryant \ AppData \ Local \ Temp \ cckEPS7f.o binaryrepresentation.cpp :( . text 0x133):未定义引用printChar(char,std :: ostream&)'C:\ Users \ Bryant \ AppData \ Local \ Temp \ cckEPS7f.o binaryrepresentation.cpp :( . text 0x16e):未定义引用printShort(int,std :: ostream&)'C:\ Users \ Bryant \ AppData \ Local \ Temp \ cckEPS7f.o binaryrepresentation.cpp :( . text 0x1a7):未定义引用printFloat(int,std :: ostream&)'c:\ program files(x86)\ dev-cpp \ mingw64 \ x86_64-w64-mingw32 \ bin \ ld.exe C:\用户\ Bryant \ AppData \ Local \ Temp \ cckEPS7f.o:错误的reloc地址0xc在.xdata'C:\ Users \ Bryant \ SkyDrive \ Documents \ Data Structures 2014 \ collect2.exe [错误] ld返回1退出状态


这是我的司机

#include <iostream>
using namespace std;
#include "display.h"

union FloatValue
{
int intView;
float floatView;
};

main()
{
cout    << "----------------------------Menu-------------------------" << endl
        << " 1 - Print the binary representation of a character" << endl
        << " 2 - Print the binary representation of a short integer" << endl
        << " 3 - Print the binary representation of a float" << endl
        << " 4 - Exit Program";

cout << "Enter your selection: ";
int selection = 0;
cin >> selection;

while (selection != 4)
{
    char charInput = '0';
    short int intInput = 0;
    switch(selection)
    {
        case 1: cout << "\nEnter a character: ";
                cin >> charInput;
                printChar(charInput, cout);
                break;
        case 2: cout << "\nEnter a short: ";
                cin >> intInput;
                printShort(intInput, cout);
                break;
        case 3: cout << "\nEnter a short: ";
                FloatValue num;
                cin >> num.floatView;
                printFloat(num.intView, cout);
                break;
        case 4: break;
    }
    cout << "\nEnter your selection: ";
    cout    << "----------------------------Menu-------------------------" << endl
        << " 1 - Print the binary representation of a character" << endl
        << " 2 - Print the binary representation of a short integer" << endl
        << " 3 - Print the binary representation of a float" << endl
        << " 4 - Exit Program";
    cin >> selection;
}

}


这是我的 Headers “display.h”

//          display.h

/*
    Basic operations:
    Print a char
    Print a short int
    Print a float
*/
#include <iostream>

void printChar(char val, ostream & out);
/* -----------------------------------
    Prints the binary representation of a user inputed character

    Receives: A char value from user
*/

void printShort(int val, ostream & out);
/* ------------------------------------
    Prints the binary representation of a user inputed integer

    Receives: An integer value from user
*/

void printFloat(int val, ostream & out);
/* ------------------------------------
    Prints the binary representation of a user inputed float

    Receives: A float-converted-to-int value from user
*/

当我尝试编译我的头文件时,我得到了上面列出的相同错误,但是当我编译我的实现文件时,我得到了一个不同的错误 .

[错误] iostream:没有这样的文件或目录

这是我的实现文件“display.cpp”

#include <iostream>
using namespace std;
#include "display.h"


// --- Utility Functions

union FloatVal;

// --- Definition of Utility Function-----------------------------------------

union FloatVal
{
    int intView;
    float floatView;
};


// --- Definition of printChar ----------------------------------------------

void printChar(char val, ostream & out)
{

    int dataSize = sizeof(char)* 8;
    unsigned char mask = 2 ^ (dataSize - 1);

    for(int dataSize; dataSize > 0; dataSize--)
    {
        int counter = 0;
        if(counter == 4)
        {
            out << " ";
            counter = 0;
        };
        if((val & mask) != 0)
        {
            out << "1";
        }

        else
        {
            out << "0";
        };

        mask >> 1;
        counter++;
    }
}

// --- Definition of printShort----------------------------------------------

void printShort(int val, ostream & out)
{
    int dataSize = sizeof(short int)* 8;
    unsigned int mask = 2 ^ (dataSize - 1);

    for(int dataSize; dataSize > 0; dataSize--)
    {
        int counter = 0;

        if(counter == 4)
        {
            out << " ";
            counter = 0;

        }

        if((val & mask) != 0)
        {
            out << "1";
        }

        else
        {
            out << "0";
        };

        mask >> 1;
        counter++;

    }
}

// --- Definition of printFloat-----------------------------------------------

void printFloat(int val, ostream & out)
{

    int dataSize = sizeof(float)* 8;
    unsigned int mask = 2 ^ (dataSize - 1);

    for(int dataSize; dataSize > 0; dataSize--)
    {
        int counter = 0;

        if(counter == 4)
        {
            out << " ";
        }

        if((val & mask) != 0)
        {
            out << "1";
        }

        else
        {
            out << "0";
        };

        mask >> 1;
        counter++;
    }
}

我试图寻找错误的解决方案,但几乎所有帖子都是关于linux用户的,以及那些从未回答过问题的帖子 .