• Advertisement
Sign in to follow this  

C++ Primer - CodeBlocks

This topic is 1439 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was just going to finish the first chapter of C++ Primer(nothing difficult :P ). When I came across

 

#include <iostream>
#include "Sales_item.h"
int main()
{
  Sales_item book;
  // read ISBN, number of copies sold, and sales price
  std::cin >> book;
  // write ISBN, number of copies sold, total revenue, and average price
  std::cout << book << std::endl;
  return 0;
}

I went to the site the book suggested. Downloaded the MS Visual Studio 2012 files. Then I tried to link the libraries to my project in CodeBlocks and my compiler did not recognise the library "Sales_item.h". Could you help me solve this problem?

Share this post


Link to post
Share on other sites
Advertisement
Sales_item.h is a header file which you'll find in folder "1" of the .zip you linked to. Most likely the problem is because code::blocks starts looking for this file from a different "starting point" (= working directory) than visual studio.

I'm not familiar with this IDE but I think you could try copying the header file to the directory where the *.cbp (= project file) is located.

EDIT: also take a look at this Edited by molehill mountaineer

Share this post


Link to post
Share on other sites

By default, Code::Blocks creates a subfolder for new projects, with the name of the project. Check where the project file is located (*.cbp). The *.cpp and *.h should be in the same folder; otherwise you have to add the include folders in the project settings, as explained in the link provided by molehill mountaineer. Do not follow the "workaround" shown there, this is bad practice.

Share this post


Link to post
Share on other sites

The next time you get something like this look at the makefile that is specified with the code or the project files, they will tell you how this is compiling. In this case it just compiles all files in the directories as separate exes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement