473,657 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is wrong with this simple code!?

10 points (and a cookie) to whoever tells me why this code generates
these errors:

C:\Programming\ Microsoft Visual Studio\MyProjec ts\HelloWorld\m ain.c(5)
: error C2065: 'cout' : undeclared identifier
C:\Programming\ Microsoft Visual Studio\MyProjec ts\HelloWorld\m ain.c(5)
: error C2297: '<<' : illegal, right operand has type 'char [2]'

#include <iostream.h>

int main()
{
cout << "h";
return 0;
}

Thanks
iw****@gmail.co m

Aug 27 '05 #1
5 10044
IW****@gmail.co m wrote:
10 points (and a cookie) to whoever tells me why this code generates
these errors:

C:\Programming\ Microsoft Visual Studio\MyProjec ts\HelloWorld\m ain.c(5)
error C2065: 'cout' : undeclared identifier C:\Programming\ Microsoft Visual Studio\MyProjec ts\HelloWorld\m ain.c(5)
error C2297: '<<' : illegal, right operand has type 'char [2]'


#include <iostream.h>


Should be

#include <iostream>
using std::cout;

int main()
{
cout << "h";
return 0;
}

Thanks
iw****@gmail.co m


Rename the file to .cpp or .C or .cxx or .c++ or anything that would
make it a C++ source file. Your compiler apparently attempts to treat
it as a C source file.

V
Aug 27 '05 #2

IW****@gmail.co m wrote:
10 points (and a cookie) to whoever tells me why this code generates
these errors:

C:\Programming\ Microsoft Visual Studio\MyProjec ts\HelloWorld\m ain.c(5)
: error C2065: 'cout' : undeclared identifier
C:\Programming\ Microsoft Visual Studio\MyProjec ts\HelloWorld\m ain.c(5)
: error C2297: '<<' : illegal, right operand has type 'char [2]'

#include <iostream.h>
It should be
#include <iostream>
int main()
{
cout << "h";


std::cout << "h" << std::endl;

Aug 27 '05 #3
I see... so I could using "using namespace std;" then if I wanted to
just make it "cout" and not "std::cout" ?

BTW, thanks for the uberly quick responses.

Aug 27 '05 #4
j

<IW****@gmail.c om> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com...
I see... so I could using "using namespace std;" then if I wanted to
just make it "cout" and not "std::cout" ?

BTW, thanks for the uberly quick responses.


The namespaces are there for a reason, so your code does not trip-over some
other library code, so it is not a good idea just to discard the namespaces.
Try getting use to writing std:: and use namespaces in your own code too..
with code completion and copy & paste it really is not that hard to get used
to..

Jesper
Aug 27 '05 #5
IW****@gmail.co m wrote:

10 points (and a cookie) to whoever tells me why this code generates
these errors:

C:\Programming\ Microsoft Visual Studio\MyProjec ts\HelloWorld\m ain.c(5)
: error C2065: 'cout' : undeclared identifier
C:\Programming\ Microsoft Visual Studio\MyProjec ts\HelloWorld\m ain.c(5)
: error C2297: '<<' : illegal, right operand has type 'char [2]'


In addition:

C:\Programming\ Microsoft Visual Studio\MyProjec ts\HelloWorld\m ain.c
***

If you haven't changed anything else, than VC++ assumes this is C code not C++.
For C++ use a file extension of *.cpp

--
Karl Heinz Buchegger
kb******@gascad .at
Aug 29 '05 #6

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

Similar topics

220
19000
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
1
5969
by: learningGuy | last post by:
Can someone tell me what is wrong with this simple code? I get an exception every time at the myFile.Open() line. I have included the code that I think is needed to for you to answer this below: Thanks! ============ // MBT.cpp : Defines the entry point for the console application. // #include "stdafx.h"
125
14703
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
121
10025
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
46
4197
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do believe MSFT should do to improve C#, however. I know that in the "Whidbey" release of VS.NET currently
2
1797
by: Phil Certain | last post by:
Hi, Relative newbie to .Net but experienced with classic ASP. I am trying to create a simple business object to contain commonly used functions. This is what I have done: 1 - Created a simple vb file containing: Imports System.Data.SqlClient Imports System.Web.HttpUtility
98
4568
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
2
2568
by: Tarik Monem | last post by:
OK! I've gone through a few tutorials and I cannot understand what I'm doing wrong casting_registration.php <table> <tr> <td> <form enctype="multipart/form-data" action="thankyou.php" method="post" name="registrationform"> Choose a shows:
20
2806
by: Daniel.C | last post by:
Hello. I just copied this code from my book with no modification : #include <stdio.h> /* count characters in input; 1st version */ main() { long nc; nc = 0;
24
3087
by: MU | last post by:
Hello I have some code that sets a dropdownlist control with a parameter from the querystring. However, when the querystring is empty, I get an error. Here is my code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then
0
8402
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
8315
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
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
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...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
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
7341
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...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.