如果我在一个文件中工作,更改到另一个缓冲区,然后更改回来,我丢失了我的撤消历史记录.
有没有解决这个问题?
在Python中接受带小数的用户输入时我正在使用:
#will input meal subtotal
def input_meal():
mealPrice = input('Enter the meal subtotal: $')
mealPrice = float (mealPrice)
return mealPrice
Run Code Online (Sandbox Code Playgroud)
它确切地返回输入的内容 - 比如$ 43.45
但是当使用该值来计算和显示我正在使用的税时:
#will calculate 6% tax
def calc_tax(mealPrice):
tax = mealPrice*.06
return tax
Run Code Online (Sandbox Code Playgroud)
使用返回$ 2.607的显示
mealPrice = input_meal()
tax = calc_tax(mealPrice)
display_data(mealPrice, tax)
Run Code Online (Sandbox Code Playgroud)
我怎样才能将其设置为2.61美元?
原谅我,我意识到这是基本的东西,但他们并没有把它简称为Intro ...
谢谢!
我正在尝试创建一个通用类来编写和从文件中读取对象.称之为ActiveRecord类
只有一个方法,它保存类本身:
void ActiveRecord::saveRecord(){
string fileName = "data.dat";
ofstream stream(fileName.c_str(), ios::out);
if (!stream) {
cerr << "Error opening file: " << fileName << endl;
exit(1);
}
stream.write(reinterpret_cast<const char *> (this), sizeof(ActiveRecord));
stream.close();
}
Run Code Online (Sandbox Code Playgroud)
现在我用User类扩展这个类:
class User : public ActiveRecord
{
public:
User(void);
~User(void);
string name;
string lastName;
};
Run Code Online (Sandbox Code Playgroud)
创建和保存用户我想做的事情如下:
User user = User();
user.name = "John";
user.lastName = "Smith"
user.save();
Run Code Online (Sandbox Code Playgroud)
如何让这个ActiveRecord :: saveRecord()方法获取任何对象和类定义,以便它写出我发送的任何内容:
看起来像:
void ActiveRecord::saveRecord(foo_instance, FooClass){
string fileName = "data.dat";
ofstream stream(fileName.c_str(), ios::out);
if (!stream) {
cerr << "Error …
Run Code Online (Sandbox Code Playgroud) 如何在允许用户输入定义向量名称的同时在c ++中声明向量?好的,在审核了您的回复之后,这里有更详细的信息; 以下是来自VS08 C++控制台应用程序的错误消息 -
Error 2 error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'std::istream' to 'char *' e:\c++\project 5\project 5\project 5.cpp 58 project 5
Run Code Online (Sandbox Code Playgroud)
这是代码:
void addRecord()
{
vector<char>recordName;
vector<inventory>recordNameUser;
cout << "Name the record you want to store it as\n";
cin.get(cin, recordName);
cout << "Enter the item description\n";
cin.get(cin, recordNameUser.itemDescription);
cout << "Enter the quanity on hand\n";
cin >> recordNameUser.quanityOnHand;
cout << "Enter the wholesale cost\n";
cin >> recordNameUser.wholesaleCost;
cout << "Enter the retail …
Run Code Online (Sandbox Code Playgroud)