我正在做一些非常基本的编码,用于在C++中使用Visual Studio 2015制作收据。我无法用空格创建名称而不被强制使用下划线(例如,Item 1 vs Item_1)。我觉得这是一个简单的解决方法,但我对编码整体而言是非常新的。无法在变量名称中放入空格 - Visual Studio 2015(C++)
或者如果有什么只是输出(收据)显示项目1而不是Item_1。
这是我当前的代码:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
double Item_1;
double Item_2;
double Item_3;
double Total;
Item_1 = 2.50;
Item_2 = 0.75;
Item_3 = 12.98;
Total = Item_1 + Item_2 + Item_3;
cout << "Thank you for shopping at StuffMart" << endl;
cout << "Item_1 = " << Item_1 << endl;
cout << "Item_2 = " << Item_2 << endl;
cout << "Item_3 = " << Item_3 << endl;
cout << "Total = " << Total << endl;
system("pause");
return 0;
}
您找到了修复程序。你也可以做camelCasing。 – ChiefTwoPencils
在C++中有标识符的规则:http://www.c4learn.com/cplusplus/cpp-variable-naming/ –