473,761 Members | 9,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"cl HelloWorld.cpp" => "std.afx" not found

Hi All,

I've got Visual Studio .Net installed, but I don't know it very well.
So I tried to create a plain old Win32 using the command-line complier.
I tried to compile:

************ HelloWorld.cpp *************
#include "stdafx.h"

void main()
{
printf("Hello, World\n");
}
*************** ** (end) *************** ****

with the command "cl HelloWorld.cpp" and got:
"HelloWorld.cpp (1) : fatal error C1083: Cannot open include file: 'stdafx.h':
No such file or directory"/
I thought that some environment variable that the compiler wanted
wasn't there, so I ran vcvars32.bat, but that didn't help.

I checked stdafx.h's (and stdafx.cpp's) existence/location: I found a
slew of them in:
F:\Program Files\Microsoft Visual Studio 8\VC\VCWizards\ AppWiz
subdirectories:
.NET\ClassLibra ry\Templates\10 33
.NET\Console\Te mplates\1033
.NET\WinForm\Te mplates\1033
Generic\Applica tion\Templates\ 1033


I suspect that all the stdafx header/program files are centered on .Net
connections so that I need to reinstall VC6.0 (and its Service Packs if
I can find them).

Any suggestions/opinions.

TIA,
Richard

Mar 21 '06 #1
9 6078
* Richard Lionheart:

I've got Visual Studio .Net installed, but I don't know it very well.
So I tried to create a plain old Win32 using the command-line complier.
I tried to compile:

************ HelloWorld.cpp *************
#include "stdafx.h"

void main()
{
printf("Hello, World\n");
}
*************** ** (end) *************** ****


Since you're posting to a C++ group, why didn't you try a C++ program?

Search the web for C++ "Hello, world!".

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 21 '06 #2
"Richard Lionheart" <RL******@USCom puterGurus.com> wrote in message
news:11******** **************@ v46g2000cwv.goo glegroups.com
Hi All,

I've got Visual Studio .Net installed, but I don't know it very well.
So I tried to create a plain old Win32 using the command-line
complier. I tried to compile:

************ HelloWorld.cpp *************
#include "stdafx.h"

void main()
{
printf("Hello, World\n");
}
*************** ** (end) *************** ****

with the command "cl HelloWorld.cpp" and got:
"HelloWorld.cpp (1) : fatal error C1083: Cannot open include file:
'stdafx.h': No such file or directory"/
I thought that some environment variable that the compiler wanted
wasn't there, so I ran vcvars32.bat, but that didn't help.

I checked stdafx.h's (and stdafx.cpp's) existence/location: I found a
slew of them in:
F:\Program Files\Microsoft Visual Studio 8\VC\VCWizards\ AppWiz
subdirectories:
.NET\ClassLibra ry\Templates\10 33
.NET\Console\Te mplates\1033
.NET\WinForm\Te mplates\1033
Generic\Applica tion\Templates\ 1033


I suspect that all the stdafx header/program files are centered on
.Net connections so that I need to reinstall VC6.0 (and its Service
Packs if I can find them).

Any suggestions/opinions.

TIA,
Richard


This is Microsoft specific. Such questions are better asked in

microsoft.publi c.vc.language

or

microsoft.publi c.vc.ide_genera l

Microsoft's compiler offers the option of pre-compiled headers, which, once
compiled, reduce compilation times. This is usually accomplished with a pair
files:

stdafx.h
stdafx.cpp

The first contains widely used inclusions, e.g.,

#include <windows.h>
#include <vector>

the second just #includes stdafx.h.

The contents of stdafx.h can vary from project to project. If you want to
use these, then you either have to define them yourself or let the IDE's
wizard generate them for you when you create a project.

For simple hello world type applications, you may wish to forget about
precompiled headers entirely. If so, just delete any reference to stdafx.h
from your source files and #include whatever headers you need in the usual
way.
--
John Carson

Mar 21 '06 #3
Richard Lionheart wrote:
Hi All,

I've got Visual Studio .Net installed, but I don't know it very well.
So I tried to create a plain old Win32 using the command-line complier.
I tried to compile:

************ HelloWorld.cpp *************
#include "stdafx.h"
// this header is non standard
void main()
// main ALWAYS returns an int
{
printf("Hello, World\n");
}
*************** ** (end) *************** ****

with the command "cl HelloWorld.cpp" and got:
"HelloWorld.cpp (1) : fatal error C1083: Cannot open include file: 'stdafx.h':
No such file or directory"/


You don't need it, so don't include it at the top.

If you need to know how to use your compiler, then post to a newsgroup
where use of your compiler is topical.

Hello world in C++ is:

#include <iostream>

int main() {
std::cout << "Hello World" << std::endl;
}

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Mar 21 '06 #4
Ben Pope <be************ ***@gmail.com> wrote:
Hello world in C++ is:

#include <iostream>
#include <ostream> // for std::endl
int main() {
std::cout << "Hello World" << std::endl;
}


Some compilers may or may not implicitly #include <ostream> in
<iostream> (for example, HP aCC's standard library does not).

--
Marcus Kwok
Mar 21 '06 #5
Marcus Kwok wrote:
Ben Pope <be************ ***@gmail.com> wrote:
Hello world in C++ is:

#include <iostream>


#include <ostream> // for std::endl
int main() {
std::cout << "Hello World" << std::endl;
}


Some compilers may or may not implicitly #include <ostream> in
<iostream> (for example, HP aCC's standard library does not).


I knew I'd get it wrong :)

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Mar 21 '06 #6
Hi Ben,

Great reply. I got a warning to add a switch:

cl HelloWorld.cpp /EHsc

Got HelloWorld.obj.

I'm 95% home! I've got to find another switch to get the .exe.

Thank you very much for posting a correct version.

Regards,
Richard

Mar 21 '06 #7
Hi Ben,

< I knew I'd get it wrong :)

You didn't get it wrong this time!!

Regards,
Richard

Mar 21 '06 #8
Hi John,

Thanks for reminders. I used to know that but I've been out of the
programming business for 5 years. You'd be surprised at how much one
can forget in that time.

Regards,
Richard

Mar 21 '06 #9
Hi Marcus,

Thanks for the additional info. Happily, it wasn't problem in in
Visual Studio .Net environment. I'm accessing via the command line to
avoid the way VS has complicated things in VC++, or that's how it seems
to me.

Ben Pope's suggestion worked great after a applied the compiler
direction to add some flags.

Regards,
Richard

Mar 21 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
4405
by: Alexander Mahr | last post by:
Dear Newsgroup, I'm somehow confused with the usage of the static keyword. I can see two function of the keyword static in conjunction with a data member of a class. 1. The data member reffers in all objects of this class to the same data Or in other word by using the static keyword all objects of one class can share data. (This is what I want)
15
2669
by: Marc Le Roy | last post by:
Hello, ADA Ravenscar is a restricted subset of the ADA language that has been defined for real-time software development in safety critical applications. Completed with additional restrictions like the ones defined in the SPARK profile, it allow to build very deterministic applications that support automatic static code analysis and schedulability analysis. http://www.acm.org/pubs/articles/proceedings/ada/289524/p1-dobbing/p1-dobbing.pdf...
17
3516
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example using std::cin; using std::cout;
8
4374
by: Douglas | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, The following code does not compile if line 3 is uncommented "using namespace std". I do not understand it. Could somebody explain it to me? I am using MSVC 6.0. Thanks a lot,
14
2172
by: john.burton.email | last post by:
I've done some extensive searching and can't seem to find an answer to this - Is it correct to using "using" with templates, for example: using std::vector; Or do I need to specify the type too: using std::vector<int>; Both seem to "work" on the compiler I have and I can't find any documentation saying which is correct, or are both correct?
6
4525
by: AlexD_UK | last post by:
When I create a new C++ project of type "Class Library (.NET)", I am unable to then add the following line of code : using namespace std If I do, I get the following error on compilation : c:\Research\Code\Visual Studio\TestC++2\TestC++2.h(7): error C2871: 'std' : a namespace with this name does not exist If I try this with other project types, e.g. "Console Application (.NET)" projects, I have no such problem.
30
4117
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" << std::endl; Myself I am not sure which I prefer, it is certainly easier to specify that the std namespace is being used instead of tagging each member of the namespace?
5
2275
by: Diwa | last post by:
Does the "value" type (value as in key-value pair )of "std::map" require a default ctor even if it is not used ? If I comment out Line 1 in the code attached later, i.e remove the default ctor of "value" type of map, I get the following error: // -------------------------------------------- /usr/include/c++/3.2.3/bits/stl_map.h:225: no matching function for call to `FieldType::FieldType()'
2
4440
by: Colonel | last post by:
It seems that the problems have something to do with the overloading of istream operator ">>", but I just can't find the exact problem. // the declaration friend std::istream & operator>(std::istream & in, const Complex & a); // the methods correspond to the friend std::istream & operator>(std::istream & in, const Complex & a) { std::cout << "real: ";
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.