0

I've been completing the exercises in a book to learn C++.

Exercise 1.20: http://www.informit.com/title/032174113 contains a copy of Sales_item.h in the Chapter 1 code directory. Copy that file to your working directory. Use it to write a program that reads a set of book sales transactions, writing each transaction to the standard output.

First off, the link they provided wasn't working. However, I got around this by finding the code on GitHub. However, I am extremely confused on how to add this to my directory. To be honest, I don't even know what that means? Could someone please explain how to add this code into your library?

AstroCB
  • 12,337
  • 20
  • 57
  • 73

2 Answers2

0

id doesn't say "add to your directory", it says "copy that file to your working directory". Your working directory is the directory you put all your *.cpp and .h and project files in.

Paweł Stawarz
  • 3,952
  • 2
  • 17
  • 26
  • 1
    Download it and place in the given directory... I don't know how to make that easier to understand. Help on browsing directories: http://support.apple.com/kb/TA20520?viewlocale=en_US – Paweł Stawarz Feb 09 '14 at 03:57
  • Ok sorry I feel retarded. So I download the text file and put it in the folder where my main.cc file is. Its still giving me an error saying that it doesn't recognize the file. What am i doing wrong? Thanks – user2444335 Feb 09 '14 at 04:02
  • Use the `#include` preprocessor directive. It should be covered in some earlier chapter or part of the one you're reading. And yes - you got the first part right :) – Paweł Stawarz Feb 09 '14 at 04:05
  • This is my code:#include #include "Sales_item.h" int main() { Sales_item item1, item2; std::cin >> item1 >> item2; // read a pair of transactions std::cout << item1 + item2 << std::endl; // print their sum return 0; } As you can see, i used the #include. Please help and thanks for your patience :) – user2444335 Feb 09 '14 at 04:07
  • http://stackoverflow.com/questions/2557766/how-to-compile-c-program-with-multiple-files-in-xcode – Paweł Stawarz Feb 09 '14 at 04:09
  • I figured it out. Thanks so much! – user2444335 Feb 09 '14 at 04:23
0

If it is what i'm thinking, do the following.

-Copy the Sales_item.h file to your working directory(probably where your code is) -Include the Sales_item.h file in your program using:

       #include "Sales_item.h"
  • Sorry I feel stupid but what is a directory? Is this just your finder where all your files in? I put the text file I downloaded in the folder that has the main.cpp file in it and its still not recognizing it. Please help and sorry for being new and stupid. – user2444335 Feb 09 '14 at 04:04
  • @user2444335 directory=folder; Include the header to your program using `#include "Sales_item.h"` then it should recognize it. – Diego R. Alcantara Feb 09 '14 at 04:07