I noticed I managed to compiled the following code without inclusion of <string>
. Shouldn't it be giving me an error?
#include <iostream>
using namespace std;
struct Sales_data {
string book_no;
double units_sold;
double price;
};
int main() {
Sales_data book1, book2;
cout << "Please enter first transaction in format: ISBN, units sold & price" << endl;
cin >> book1.book_no >> book1.units_sold >> book1.price;
cout << "Please enter second transaction in format: ISBN, units sold & price" << endl;
cin >> book2.book_no >> book2.units_sold >> book2.price;
cout << "******************************" << endl;
cout << "Total units sold = " << book1.units_sold + book2.units_sold << endl;
cout << "Total revenue = " << (book1.units_sold * book1.price) + (book2.units_sold * book2.price) << endl;
return 0;
}
Compilation results:
[yapkm01][~/C++Primer/chapter2]# g++ -std=c++11 -o 2-41a 2-41a.cc
[yapkm01][~/C++Primer/chapter2]#