how to start with Visual Studio C++ Express

h4ever

Member
Aug 30, 2013
163
0
0
I am trying to compile my first program in the Visual Studio C++ Express.
But I still get error reports in Build output that I should insert headers.
I tried tutorial codes from this page:
http://www.cplusplus.com/doc/tutorial/classes2/
And I tried to insert only only one line of:
#include <iostream>
and deleted headers and resources from the project. Still I got error.


------ Build started: Project: test4, Configuration: Debug Win32 ------
test4.cpp
c:\projects\test4\test4\test4.cpp(2): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
Add directive to 'StdAfx.h' or rebuild precompiled header
c:\projects\test4\test4\test4.cpp(4): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What I need to correct or to set to make the program working?
 

h4ever

Member
Aug 30, 2013
163
0
0
It will still make the error or even if I create the header it will make error:
#include "iostream.h"': skipped when looking for precompiled header use
Add directive to 'StdAfx.h' or rebuild precompiled header
 

Jaydip

Diamond Member
Mar 29, 2010
3,691
21
81
It will still make the error or even if I create the header it will make error:
#include "iostream.h"': skipped when looking for precompiled header use
Add directive to 'StdAfx.h' or rebuild precompiled header
Did you select the check box "precompiled headers" when you created a win32 console application? uncheck it and create a new project.Here is a sample program

Code:
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{

cout << "Test\n" ;
getch();
return 0;
}
 
Last edited:

h4ever

Member
Aug 30, 2013
163
0
0
ctrl+shift+n evokes dialog box, where I have Win32/Win32 Consol App selected however there are no checkboxes except Create Directory for solution bellow.

However when I submit I got window with button Next where was Precompiled header checked!
 
Last edited:

h4ever

Member
Aug 30, 2013
163
0
0
First test which I succeed to do is with the default code which is there when I open new project. This one worked to compile. However

This code is success:

Code:
// test6.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}
Using this line
#include <iostream>
after
#include "stdafx.h"
will result in.... not build message shown in the window where error were. This time no message in Build dropdown menu.

If I will use your code, so it will write : invalid preprocessor command 'Include'

Now I can see what is in the file stdafx.cpp
#include "stdafx.h"

But it looks that if I try to include with the <iostream> so this returns error

Also
#include <conio.h>
is not in the project/header files
 
Last edited:

Jaydip

Diamond Member
Mar 29, 2010
3,691
21
81
First test which I succeed to do is with the default code which is there when I open new project. This one worked to compile. However

This code is success:

Code:
// test6.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}
Using this line
#include <iostream>
after
#include "stdafx.h"
will result in.... not build message shown in the window where error were. This time no message in Build dropdown menu.

If I will use your code, so it will write : invalid preprocessor command 'Include'

Now I can see what is in the file stdafx.cpp
#include "stdafx.h"

But it looks that if I try to include with the <iostream> so this returns error

Also
#include <conio.h>
is not in the project/header files

Because the "I" was in caps :) remove all files except your source code and copy paste mine, it should work.
 

Jaydip

Diamond Member
Mar 29, 2010
3,691
21
81
Thanks. But can we fix that I could see console if no input is to be waited? Make the console not to close. Also if possible to see the Build Errors by default, not those Debug. Coz I have to switch it manually permanently

I don't get you, aren't you getting a console window now? It is basically wating for input.
 

h4ever

Member
Aug 30, 2013
163
0
0
Yeah. But if I change code (to the previous code from Classes tutorial) which has no input so the console auto close itself (it prints some calculated values and then closes). Is it not possible to make it not closing?
 

Jaydip

Diamond Member
Mar 29, 2010
3,691
21
81
Yeah. But if I change code (to the previous code from Classes tutorial) which has no input so the console auto close itself (it prints some calculated values and then closes). Is it not possible to make it not closing?

Ok, make sure you have #include <conio.h> in the list of headers and getch (); as the last line before return 0;. This should solve your problem.
 

h4ever

Member
Aug 30, 2013
163
0
0
Ok. May you tell me some function which I should use if I would like to see content saved in array or in object or data structure? When I used working with programs like PHP, AHK or Javascript I always needed some function like print_r, Array_print or console.log which can print array or object content. So I need this one also here in C++.
 
Last edited:

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
If you run in the debugger, you can look at array contents when the array is in scope.

C++ does not provide you with a deserialization method. You have to roll your own.

If you do not want the getch() option in your code to see the window prior to closing, open a cmd window and run the exe from there. You may have to build in release mode.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Build output will show when doing a build. This happens before the execution
Debug will show when executing in the Debug mode.
 

h4ever

Member
Aug 30, 2013
163
0
0
Someone told me to use cl /CLR command however it fails to me to work. I've got an idea maybe I should change the command line, however how to do it?


When I click on the command line it is not editable.
 
Last edited:

h4ever

Member
Aug 30, 2013
163
0
0
I am trying to compile this code but cannot find how to include /CLR option in the compile command:

http://paste.ofcode.org/ntpebmjHEBYWdvzeX4H25p

When I try command line cl /clr test6.cpp from the folder of projects I got message that the cl program is not found. After adding source path of bin folder into system path variable and resetting it still does not work. It says it cannot find driver mspdb100.dll
 

Jaydip

Diamond Member
Mar 29, 2010
3,691
21
81
I am trying to compile this code but cannot find how to include /CLR option in the compile command:

http://paste.ofcode.org/ntpebmjHEBYWdvzeX4H25p

When I try command line cl /clr test6.cpp from the folder of projects I got message that the cl program is not found. After adding source path of bin folder into system path variable and resetting it still does not work. It says it cannot find driver mspdb100.dll

Run the batch file C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat or include this in the environment variable C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE
 

h4ever

Member
Aug 30, 2013
163
0
0
Code:
@call :GetVSCommonToolsDir
@if "%VS100COMNTOOLS%"=="" goto error_no_VS100COMNTOOLSDIR
...
Code:
:error_no_VS100COMNTOOLSDIR
@echo ERROR: Cannot determine the location of the VS Common Tools folder.

What is GetVSCommonToolsDir ??
 

Jaydip

Diamond Member
Mar 29, 2010
3,691
21
81
Code:
@call :GetVSCommonToolsDir
@if "%VS100COMNTOOLS%"=="" goto error_no_VS100COMNTOOLSDIR
...
Code:
:error_no_VS100COMNTOOLSDIR
@echo ERROR: Cannot determine the location of the VS Common Tools folder.
What is GetVSCommonToolsDir ??

you are running the batch file? first try with the second method I posted.
 

h4ever

Member
Aug 30, 2013
163
0
0
OK. I got it prepared. Both paths must to be set in system PATH variable.

Now I started the compilation from command line and I have this error:

test6>cl /CLR test6.cpp
test6.cpp
test6.cpp(3) : fatal error C1034: windows.h: no include path set
 

Jaydip

Diamond Member
Mar 29, 2010
3,691
21
81
OK. I got it prepared. Both paths must to be set in system PATH variable.

Now I started the compilation from command line and I have this error:

test6>cl /CLR test6.cpp
test6.cpp
test6.cpp(3) : fatal error C1034: windows.h: no include path set

Include the "Include" directory in your VS installation folder.
 

h4ever

Member
Aug 30, 2013
163
0
0
Is this normal? How many folders I must set yet? I must restart my computer every time. No your fault of sure, I just complain the installation.