数据结构的新特性 一个练习题,从C++入门第五版要求编写自己的版本SaluxDATA类。< /P>

数据结构的新特性 一个练习题,从C++入门第五版要求编写自己的版本SaluxDATA类。< /P>,c++,string,data-structures,c++11,C++,String,Data Structures,C++11,我是这样做的 #include <iostream> #include <string> struct sales data { string bookno; unsigned int books sold; double revenue; }; int main() { return 0; } 这个 应该是 struct sales_data 请注意下划线。 标识符或类型名称中的空格不合法 这个 应该是 struct sales_

我是这样做的

#include <iostream>
#include <string>

struct sales data
{
    string bookno;
    unsigned int books sold;
    double revenue;
};

int main()
{
    return 0;
}
这个

应该是

struct sales_data
请注意下划线。 标识符或类型名称中的空格不合法

这个

应该是

struct sales_data
请注意下划线。
标识符或类型名称中的空格不合法

第一个问题:在名称
sales\u data
books\u sales
中忘记了下划线(或其他字符)。标识符在C++中不能包含空格:

struct sales_data
//          ^

unsigned int books_sold;
//                ^
第二个问题:您应该使用它所属的命名空间限定
字符串

    std::string bookno;
//  ^^^^^
或者在使用非限定的
字符串
名称之前,对其进行
使用
声明:

using std::string;
这是您的程序在所有上述修复后的外观:

#include <iostream> // You don't seem to need this for this program
#include <string>

struct sales_data
{
    std::string bookno;
    unsigned int books_sold;
    double revenue;
};

int main()
{
    return 0;
}
#include//您似乎不需要此程序
#包括
结构销售数据
{
std::字符串书号;
未签名的整版图书已售出;
双重收入;
};
int main()
{
返回0;
}

第一个问题:您在名称
sales\u data
books\u sales
中忘记了下划线(或其他字符)。标识符在C++中不能包含空格:

struct sales_data
//          ^

unsigned int books_sold;
//                ^
第二个问题:您应该使用它所属的命名空间限定
字符串

    std::string bookno;
//  ^^^^^
或者在使用非限定的
字符串
名称之前,对其进行
使用
声明:

using std::string;
这是您的程序在所有上述修复后的外观:

#include <iostream> // You don't seem to need this for this program
#include <string>

struct sales_data
{
    std::string bookno;
    unsigned int books_sold;
    double revenue;
};

int main()
{
    return 0;
}
#include//您似乎不需要此程序
#包括
结构销售数据
{
std::字符串书号;
未签名的整版图书已售出;
双重收入;
};
int main()
{
返回0;
}

它应该是
std::string
-您忘记了名称空间限定符。我不知道struct属于std。无论如何,它仍然会给出相同的错误。它应该是
std::string
-您忘记了名称空间限定符。我不知道struct属于std。无论如何,它仍然给出相同的错误;还是一样的错误。也添加了下划线。没有帮助。好的,现在它显示错误:以前需要不合格的idstruct@judas:好的,很高兴helped@judas如果这回答了你的问题,你能考虑把答案标记为被接受吗?(或者其他用户可能喜欢的任何其他答案,当然)使用名称空间std添加;还是一样的错误。也添加了下划线。没有帮助。好的,现在它显示错误:以前需要不合格的idstruct@judas:好的,很高兴helped@judas如果这回答了你的问题,你能考虑把答案标记为被接受吗?(或者其他用户可能更喜欢的任何其他答案)@user1929959,也是这样。好的,现在它说的是错误:以前需要不合格的idstruct@user1929959好的,现在它说的是错误:在struct之前应该是非限定id