我正在做一些非常基本的編碼,用於在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/ –