1

这是我的第三个 C++ 应用程序,所以我是初学者。请看下面的代码

主文件

#include<iostream>
#include <string>
#include "GradeBook.h"

using namespace std;

int main()
{
    GradeBook myGradeBook1("Java");
    GradeBook myGradeBook2("C++");

    cout << "Course Name is: " << myGradeBook1.getCourseName() << endl;
    cout << "Course Name2 is: " << myGradeBook2.getCourseName() << endl;
}

成绩簿.h

#include <iostream>
#include <string>

using namespace std;

class GradeBook
{
private:
    string courseName;

public:

    GradeBook(string name)
    {
        setCourseName(name);
    }

    void setCourseName(string name)
    {
        courseName = name;
    }

    string getCourseName()
    {
        return courseName;
    }

    void displayMessage()
    {
        cout << "Welcome to " << getCourseName() << endl;
    }
};

现在,当我运行程序时(我使用 netbeans,编译器是 cygwin),它给出了以下错误:

> "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS=
> .build-conf make[1]: 进入目录
> `/cygdrive/c/Users/Yohan/Documents/NetBeansProjects/LearnCPlusPlus'
> "/usr/bin/make" -f nbproject/Makefile-Debug.mk
> dist/Debug/Cygwin-Windows/learncplusplus.exe make[2]: 进入
> 目录
> `/cygdrive/c/Users/Yohan/Documents/NetBeansProjects/LearnCPlusPlus'
> mkdir -p 构建/调试/Cygwin-Windows rm -f
> 构建/调试/Cygwin-Windows/ClassWithPara.od g++ -c -g -MMD -MP -MF
> 构建/调试/Cygwin-Windows/ClassWithPara.od -o
> 构建/调试/Cygwin-Windows/ClassWithPara.o ClassWithPara.cpp
> ClassWithPara.cpp:28:4: 警告:文件 mkdir -p 末尾没有换行符
> dist/调试/Cygwin-Windows g++ -o
> dist/调试/Cygwin-Windows/learncplusplus
> 构建/调试/Cygwin-Windows/IfStatement.o
> 构建/调试/Cygwin-Windows/ClassWithConstructors.o
> 构建/调试/Cygwin-Windows/HelloWorld.o
> 构建/调试/Cygwin-Windows/ClassWithSetters.o
> 构建/调试/Cygwin-Windows/ClassWithPara.o
> 构建/调试/Cygwin-Windows/FirstClass.o
> 构建/调试/Cygwin-Windows/AddIntegers.o  
> nbproject/Makefile-Debug.mk:68:目标配方
> `dist/Debug/Cygwin-Windows/learncplusplus.exe' 失败 make[2]: 离开
> 目录
> `/cygdrive/c/Users/Yohan/Documents/NetBeansProjects/LearnCPlusPlus'
> nbproject/Makefile-Debug.mk:65:目标“.build-conf”的配方失败
> make[1]: 离开目录
> `/cygdrive/c/Users/Yohan/Documents/NetBeansProjects/LearnCPlusPlus'
> nbproject/Makefile-impl.mk:39:目标“.build-impl”的配方失败
> /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(libcmain.o):在
> 功能“主要”:
> /usr/src/debug/cygwin-1.7.16-1/winsup/cygwin/lib/libcmain.c:39:
> 未定义对 `_WinMain@16' collect2 的引用:ld 返回 1 退出
> 状态 make[2]: *** [dist/Debug/Cygwin-Windows/learncplusplus.exe]
> 错误 1 ​​make[1]: *** [.build-conf] 错误 2 make: *** [.build-impl]
> 错误 2
>
>
> BUILD FAILED(退出值2,总时间:11s)
4

1 回答 1

1

那里唯一的具体信息说

ClassWithPara.cpp:28:4: warning: no newline at end of file mkdir -p

您是否尝试过在该文件末尾添加换行符?

(从技术上讲,这是必需的,尽管并不总是强制执行。)从您给出的输出中不清楚这是否真的只是一个警告,或者它是否被视为错误。

于 2012-07-31T21:47:20.940 回答