Solved

from a tutorial, import a folder of code examples

Posted on 2014-09-14
19
178 Views
Last Modified: 2014-09-21
http://www.wiley.com/WileyCDA/WileyTitle/productCd-111882377X.html
CPP_Programs_from_Book.zip

from c++ for dummies (7th edition: latest)

there is a folder with many folders (chapter 1 folder, chapter 2 folder)

There are no instructions in the beginning of the book to add this folder to visual studio express 2013, instead recommending code::blocks program.

I have previously worked with visual studio express 2013 (using c (not c++)) and I could only add one file to the solution explorer at a time because if another file had an error I could not compile any file
0
Comment
Question by:rgb192
  • 7
  • 7
  • 5
19 Comments
 
LVL 32

Expert Comment

by:phoffric
ID: 40323463
Since you have a book that recommends the code::blocks program, I recommend that you download it. Otherwise, you will have to build your VS solutions and projects, one by one, and fill them in with the source code.

For example, you could have a Chapter2 solution consisting of two projects, FloatAverage and IntAverage. Then in both projects, you would have to Add Existing Items, which in this case is just the corresponding main.cpp. Looks like your Chapter16 solution would have 11 projects, each with only one source code file, named main.cpp.

I do see some .depend files, which may make your VS life more complicate if it means that one project is dependent upon another project being built first. (I am not sure about that since I do not have any code::blocks program experience.)

Another solution is to find a tutorial book that is geared towards Visual Studio.
0
 

Author Comment

by:rgb192
ID: 40323476
I already bought the physical soft cover book.
I thought this would be an easy answer such as paste the 'c++ for dummies' code folder in
c:\users\acer\documents\visual studio 2013\Projects

creating only one project.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 40323496
It looks to me like they have one "solution" per chapter, and multiple projects per chapter. For the most part, if you use VS, there is only one main.cpp file per project, so that isn't so much to load. Only in latter chapters do I see .depend files, but by that time, you should be able to understand what needs to be done in VS.

In general, you cannot create "only one project" since there are many main.cpp files, and each one has a main() function. And, as you know, there can be at most one main() function per project. (Some projects have no main() functions if they are to become a library.)
0
 

Author Comment

by:rgb192
ID: 40323510
so create a new solution for chapter1 and copy and paste code folder for chapter1so create a new solution for chapter1 and copy and paste code folder for chapter1


Only in latter chapters do I see .depend files, but by that time, you should be able to understand what needs to be done in VS.
I am looking for a solution for chapters in the beginning and then my experience will be better and I will ask you questions about chapters in the end of book
0
 
LVL 32

Expert Comment

by:sarabande
ID: 40323696
can you post a picture of the chapter1 folder?

as phoffric told you would create one solution per chapter and one project for each subfolder.

unfortunately, visual studio makes it difficult to create solely a solution and add projects to it, then.

the easiest way to go on, is to create an 'empty project' named chapter1 and have the checkbox 'create directory for solution' checked.

after that select the project 'chapter1' in the solution tree and delete it by 'DEL' key.

you now have an empty solution.

then right-click on the solution in solution tree and choose 'new project'.

select 'win32 console application' and name it like the first project in the tutorial.

step to 'next' page when the project wizard arises.

first, uncheck 'precompiled headers' and next select 'empty project'.

after that you could copy the sources for the project into the newly created subfolder by windows explorer.

then in visual studio add the sources to the project as described by phoffric.

after that you may build the project. if there are compile or build errors, post them here.

repeat the above for all projects of chapter1.

note, the dependencies between the projects can be created easily in visual studio. for using header files of project projectx in projecty, add the folder as a relative path (like ..\projectx) to the include folders (project - properties - configuration properties - vc directories - include directories + 'all configurations') of current projecty. the dependencies between projects can be set by right-clicking on the dependent project in solution tree and choose 'project dependencies...'.

Sara
0
 

Author Comment

by:rgb192
ID: 40323829
http://media.wiley.com/product_ancillary/7X/11188237/DOWNLOAD/CPP_Programs_from_Book.zip

and this is chapter1 picture

one folder in chapter1 folder
there is one folder in the chapter1 folder
0
 
LVL 32

Expert Comment

by:sarabande
ID: 40324188
the .layout and .cbp files are project and configuration files for code::blocks.

you may try to copying the main.cpp only and add it as 'existing item' to project 'conversion' below solution 'chapter1'.

Sara
0
 
LVL 32

Expert Comment

by:phoffric
ID: 40324204
I recommend that you use "General" rather than "Win32" and then choose "Empty Project". This should keep all Microsoft non-portable code and now you dealing with pure ANSI/ISO C++. (Unless, of course, you want to learn now about Microsoft way of doing things, which I do not recommend for a beginner trying to learn pure C++.)
0
 

Author Comment

by:rgb192
ID: 40324642
general-emptygeneral-empty

what checkboxes should I check?

c:\users\acer\documents\visual studio 2013\Projects\dummies-chapter1
only copy paste main.cpp?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 32

Expert Comment

by:phoffric
ID: 40324650
I would make your solution name "dummies". Your project name is fine, or you could just make it Chapter01.
Assuming you don't have a dummies solution yet, then keep that checkmark to create the solution.

>> only copy paste main.cpp?
yes, or you could just put the corresponding main.cpp file in the projects folder and then add items -> existing.
0
 

Author Comment

by:rgb192
ID: 40324679
solution dummies
yes, or you could just put the corresponding main.cpp file in the projects folder and then add items -> existing.
so maybe I could have all the folder and then just add each file to project and remove from project (one file at a time)

Assuming you don't have a dummies solution yet, then keep that checkmark to create the solution.
i do not think I have a solution yet
Only one checkbox?
0
 
LVL 32

Expert Comment

by:phoffric
ID: 40324684
Looks like you noticed that when you type in a project name, as you type, the name transfers to the solution name. But did you notice that after you enter the project name, you can modify the solution name without affecting the project name?
Right, you don't have a solution yet - that's why it says create directory for solution. After you have a solution, it will say something like, do you want to add the project to current solution.

>> so maybe I could have all the folder and then just add each file to project and remove from project (one file at a time)
You could do that, but if you forget something, it's nice to be able to go back without having to add/remove.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 40324687
For project names, you might want something like: Ch05_overloadOperators so that you have an idea what the project was about.
0
 
LVL 32

Assisted Solution

by:sarabande
sarabande earned 250 total points
ID: 40324740
I would make your solution name "dummies". Your project name is fine, or you could just make it Chapter01.
 Assuming you don't have a dummies solution yet, then keep that checkmark to create the solution.
I don't think that dummies is a good solution name. same is for chapter01 which makes it difficult to associate a task or issue with the project. the theme in chapter 1 is 'conversion' what is a good project name. also chapter01 or cpp_for_dummies_01 would be a good solution name.

the checkbox in the 'new project' dialog is not for to creating a solution to the project but it would create an additional  directory for the solution. if checked you would get something like ...\projects\dummies\dummies where the solution file dummies.sln resides in the ...\projects\dummies and the project file dummies.vcxproj in ...\dummies\dummies. that rarely is a good structure.

I again recommend to first creating an empty solution by defining an empty project chapter01 and let the wizard create the two folders chapter01\chapter01 for solution and project. then, delete the project folder chapter01, both in visual studio and in the explorer, what would give you the 'empty solution'. all projects for the solution then could be created by using 'add new ... project' in the solution tree.

But did you notice that after you enter the project name, you can modify the solution name without affecting the project name?
that would rename the solution in the solution tree but would not rename the solution filenames. that is not recommendable.

Sara
0
 
LVL 32

Accepted Solution

by:
phoffric earned 250 total points
ID: 40324751
>> that would rename the solution in the solution tree
Since the solution doesn't yet exist, the name in the solution field is the name of the solution and no renaming takes place. The solution name filenames does match the solution name in the setup. At least that is the way it works for me using vs 2013 express. The project filename also matches the file name in the setup.

when adding a new project, select the option to use the existing solution to avoid a large number of solutions.

But that is your choice. Your main goal is to learn C++ and all this talk about the best way to set up your project is a distraction. Do it anyway you want and start learning C++.
0
 
LVL 32

Expert Comment

by:sarabande
ID: 40325048
all this talk about the best way to set up your project is a distraction.
hmm. it is the main point of the original question. how could it be a distraction then?

from my experience a good naming and structuring of a non-trivial project tree is the base for success. any mistakes done in this early phase can be badly corrected later or require to begin from scratch. in my opinion, the structures and names used in the book can be ported one-on-one to a visual studio project environment, what could be a precondition for following the book. it probably is even helpful when the tutorials elaborate the code::blocks management cause the visual studio would need similar handling for the projects.

Sara
0
 

Author Comment

by:rgb192
ID: 40325615
You could do that, but if you forget something, it's nice to be able to go back without having to add/remove.
i agree. Another question after I start this project.

For project names, you might want something like: Ch05_overloadOperators so that you have an idea what the project was about.
ok descriptive names for each chapter

I again recommend to first creating an empty solution by defining an empty project chapter01 and let the wizard create the two folders chapter01\chapter01 for solution and project. then, delete the project folder chapter01, both in visual studio and in the explorer, what would give you the 'empty solution'. all projects for the solution then could be created by using 'add new ... project' in the solution tree.
I do not understand. Do I need to do all these steps for each chapter in dummies tutorial?





I did general ->empty project
same scrennshot
http://filedb.experts-exchange.com/incoming/2014/09_w38/800_872399/general-empty-dummies.JPG

but with a descriptive name
chapter1-writing-first-program
which is repeated twice in the windows explorer folder location

Do I put all of chapter 1 in this folder or just the main.cpp
first chapter folder
0
 
LVL 32

Expert Comment

by:sarabande
ID: 40327627
I do not understand. Do I need to do all these steps for each chapter in dummies tutorial?
in my opinion you have two choices:

(A) create one solution 'cpp_for_dummies' and put all projects into this solution. then, the project names should contain the chapters and the topic, for example 'ch01_conversion'.

(B) create a new solution for each chapter for example 'chapter01' and add only the projects of the chapter as projects to the solution, for example project 'conversion' to solution 'chapter01'.

(A) has the advantage that the hierarchy is simple and you have all projects below one root folder. additionally advantage is that you only need to create one solution. also it is simpler to add and use a new folder for commonly used header files for all projects:

cpp_for_dummies
 |
   --- common_headers
 |
   --- ch01_conversion 

Open in new window


(B) makes it easier to follow the structure used in the book. It also may be easier to understand the purpose of the respective chapter. moreover, you may have advantages of assigning the source code to the respective folders as you probably could use the same folder names and hierarchy as used in code::blocks.

I did general ->empty project .... but with a descriptive name chapter1-writing-first-program
which is repeated twice in the windows explorer folder location
that happens if you check the 'create directory for solution' in the 'new project' dialog and use the option 'create new solution'. for your tutorial you should always create solutions and projects separately., what means you first create an empty solution and then only 'add projects' to the existing solution.

to create an 'empty solution' you do:
- open visual studio
- choose 'new project' from start page (or file menu).
- enter the name of the solution (for example 'chapter01' if you want one solution per chapter)
- check the 'create directory for solution'
- choose 'empty project' as project type
after creation:
- right-click on the new project in solution tree
- select 'Remove <DEL>' and remove the project
- close solution and exit visual studio
- delete the second folder 'chapter01' in windows explorer.

to add a new project to a solution
- open the solution in visual studio
- right-click on solution (first row) in solution tree
- choose 'add ... new project'
- enter name (like 'conversion')
- choose project type WIN32 console application
- uncheck the precompiled header option
- choose option 'empty project'
after creation:
- use windows explorer to copy the sources of the new project to new project folder
- in visual studio  right-click on the new project
- choose 'add ... existing items'
- select all copied sources of the new project folder

Do I put all of chapter 1 in this folder or just the main.cpp

you would only put sources into to the folder (other files probably are for code::blocks only)

that is .cpp, .h, .rc, .def files.

an exception to this might be .lib files or .tlb and .tlh files. these kind of files would be explained in the book if used.

if a chapter has more than one project, you only would use the files belonging to the project.

Sara
0
 

Author Closing Comment

by:rgb192
ID: 40335960
Currently on chapter 7, I am using a solution for each chapter. I will ask a followup on more complex chapters.

Thanks.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now