• Create Account

## C++ Primer - CodeBlocks

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

738
Like
1Likes
Like

Posted 14 February 2014 - 02:43 AM

I was just going to finish the first chapter of C++ Primer(nothing difficult ). 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?

Failure is not an option...

### #2molehill mountaineer  Members

595
Like
2Likes
Like

Posted 14 February 2014 - 03:00 AM

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, 14 February 2014 - 03:05 AM.

738
Like
0Likes
Like

Posted 14 February 2014 - 04:00 AM

Thanks man!! The link you posted solved my problem.

Failure is not an option...

### #4cdoubleplusgood  Members

895
Like
2Likes
Like

Posted 14 February 2014 - 04:04 AM

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.

738
Like
0Likes
Like

Posted 14 February 2014 - 04:18 AM

Thanks. Now it's far more convenient.

Failure is not an option...

### #6NightCreature83  Members

4785
Like
0Likes
Like

Posted 14 February 2014 - 06:27 AM

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.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.