关于cpp的菜鸟问题之3

来源:百度知道 编辑:UC知道 时间:2024/07/08 08:24:08
#include <iostream>
#include "Sales_item.h"
int main()
{
// declare variables to hold running sum and data for the next record
Sales_item total, trans;
// is there data to process?
if (std::cin >> total) {
// if so, read the transaction records
while (std::cin >> trans)
if (total.same_isbn(trans))
// match: update the running total
total = total + trans; // 这里啊!
else {
// no match: print & assign to total
std::cout << total << std::endl;
total = trans;
}
// remember to print last record
std::cout << total << std::endl;
} else {
// no input!, warn the user
s

一样的
a+=b;和a=a+b;是一样...怎么写都行吧~

实际效果是一样的,如果硬要说区别....
也许需要从编译器的编译原理看吧..
记得以前看过高手写的文章.
两句等价的语句,在编译的时候,编译器有可能把他们分解成不同的语句.
有可能在编译速度上有差距.
有些大的会差到数量级的区别.
具体就不清楚了~~~呵呵..我也是学习者. 哈哈
关注中~

作者自谦,primer就是初学者的意思。
所以写total = total + trans;
两个写法编译后效率一样。