c++ - 在 C++ 中打印我的变量后无法获得 $ 打印符号

标签 c++

<分区>

我不断收到此错误消息:

exit status 1

main.cpp: In function 'int main()':
main.cpp:31:68: error: unable to find string literal operator 'operator""endl' 
with 'const char [3]', 'long unsigned int' arguments

At cout<< "The total purchase value amount is ">>totalPurchase<<"$."endl;

抱歉,我是编程新手,我不知道如何解决这个问题,我知道这很简单。我只是想得到一个$。当数据打印给用户时,在我的值后面,因此它看起来格式很好。对我做错了什么的任何解释将不胜感激。 如果我删除“$”。部分它工作得很好,但它向用户显示的只是一个数字,而不是美元值(value)。

感谢您的帮助!

#include <iostream>
#include <string>
using namespace std;
int main() {

//The part is to declare our constants and variables

double totalPurchase;
double calcstatetax;
double calccountytax;
double totalsalestax;
double ultimatevalue;
double statetax = .04;
double countytax = .02;


//This part is to allow the user to input information

  cout << "Enter the amount of the purchase.";
  cin >> totalPurchase;

    //This part is our algorithm calculating the needed values

    calcstatetax = totalPurchase*statetax;
    calccountytax = totalPurchase*countytax;
    totalsalestax = calcstatetax+ calccountytax;
    ultimatevalue = totalsalestax+ totalPurchase;

      //This part displayes our calculated values to the user.

      cout<< "The total purchase value amount is "<<totalPurchase<<"$."endl;
      cout<< "The calculated state tax is "<<calcstatetax<<endl;
      cout<< "The calculated county tax is "<<calccountytax<<endl;
      cout<< "The total sales tax is "<<totalsalestax<<endl;
      cout<< "The total value of the purchase including the combined sales tax is "<<ultimatevalue<<endl;

最佳答案

main.cpp: In function 'int main()': main.cpp:31:68: error: unable to find string literal operator 'operator""endl' with 'const char [3]', 'long unsigned int' arguments

您忘记添加 <<最后一个 endl 之前的运算符:

替换:

cout<< "The total purchase value amount is "<<totalPurchase<<"$."endl;

与:

cout<< "The total purchase value amount is "<<totalPurchase<<"$." << endl;

Live Demo

关于c++ - 在 C++ 中打印我的变量后无法获得 $ 打印符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52435637/

相关文章:

c++ - #ifdef SWIG : When does this conditional compilation is taken into consideration?

c++ - 哪个是 DLL 的隐式链接和显式链接之间的最佳实践

c++ - 存储对指针的引用

c++ - 列出迭代器访问冲突

c++ - 我应该如何使用 v8::SetNativesDataBlob?

c++ - 为什么函数以相反的顺序显示十六进制代码?

c++ - 复制嵌套 vector 的最简单方法是什么

c++ - 在初始化中使用新声明的变量 (int x = x+1)?

c++ - 使用 Boost::graph 随机访问顶点

c++ - cgi 中的进程处理