从C Primer学习。预期的表达式错误Xcode

时间:2013-10-18 13:10:29

标签: c++ xcode syntax

我正在从C入门学习C ++。 我被困在这个问题的最后部分(1.6(第25页))

  

练习第2.6.2节   练习2.41:使用Sales_data类重写第1.5.1节(第22页),第1.5.2节(第24页)和第1.6节(第25页)中的练习。现在,您应该在与主函数相同的文件>中定义Sales_data类。

#include <iostream>
#include <string>

struct Sales_data 
{
    std::string Book_Name;
    unsigned Units_Sold = 0;
    double Revenue = 0.0;
};

int main()
{
    double price;
    Sales_data total;  // variable to hold data for the next transaction // read the first transaction and ensure that there are data to process
    if (std::cin >> total.Book_Name >> total.Units_Sold >> price) 
    {
        total.Revenue = total.Units_Sold * price;
        Sales_data trans; // variable to hold the running sum // read and process the remaining transactions
        while (std::cin >> trans.Book_Name >> trans.Units_Sold >> price) 
        {
            trans.Revenue = trans.Units_Sold*price;
            // if we're still processing the same book
            if (total.Book_Name == trans.Book_Name)
            {
                total.Units_Sold += trans.Units_Sold; // update the running 
                total.Revenue += trans.Revenue; // update the running 
            }
            else 
            {
            std::cout << total.Book_Name << total.Units_Sold << total.Revenue;
            **total.Book_Name = trans.Book_Name;**
            total.Units_Sold = trans.Units_Sold;
            **total.Revenue = trans.Revenue;**
            }
            **std::cout << total.Book_Name << total.Units_Sold << price << std::endl;** //print the last transaction 
        }
    }
    else 
    {
        // no input! warn the user
        std::cerr << "No data?!" << std::endl; 
        return -1; // indicate failure
    }
    return 0; 
}

哪里有** Xcode一直告诉我预期的表达..我不知道有什么不对请帮助......

2 个答案:

答案 0 :(得分:1)

根据您对我的评论的回复,当您从电子书中复制一些代码时,您引入了一些奇怪的字符。当我使用gcc复制和编译程序时,我收到了如下错误( live example here ):

error: stray ‘\357’ in program

\357是八进制转义序列。删除这些字符后,程序编译正常。

答案 1 :(得分:0)

添加到Shafik Yaghmours的答案中。

我复制了一些代码才能重新输入 float !!

  

const燕麦TEMPCOMP =(200 +(dT2 *(c6 + 100)>> 11))/ 10;

我无法复制并粘贴以显示外观。.造成两行(前后) 当我在这里过去时,看起来会一样。

但是在编辑器(Arduino)中,您可以清楚地看到区别。 浮子的f和l接触!

实际上它是Unicode字符“拉丁文小写本FL”(U + FB02)
FileFormat.info