?
Solved

Errors in simple C++ program with Visual Studio 2010 Express

Posted on 2010-09-23
9
Medium Priority
?
677 Views
Last Modified: 2013-11-27
Can someone tell me why I'm getting the errors below for the simple C++ program shown?

#include "stdafx.h"
#include <tchar.h>
#include <iostream>

#using <mscorlib.dll>
#using <System.dll>
#using <System.xml.dll>
      
using namespace System;
using namespace System::Xml;
      
void main(void)
{
      XmlTextReader^ reader = gcnew XmlTextReader ("books.xml");
      cout << reader->Read() ;
   
}

------ Build started: Project: Q815658, Configuration: Debug Win32 ------
  Q815658.cpp
Q815658.cpp(17): error C2065: 'cout' : undeclared identifier
Q815658.cpp(17): warning C4804: '<<' : unsafe use of type 'bool' in operation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Thanks for your help...
0
Comment
Question by:steva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33751062
urm not sure, I think in mfc it was okay not to specify .h but not sure about 2010

does it make a difference if you change

#include <iostream>

to

#include <iostream.h>
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33751068
or maybe specify the std lib like this

std::cout << reader->Read() ;

what is reader->Read() ; doing? is that expecting input?
0
 

Author Comment

by:steva
ID: 33751122
Actually,I made a mistake.  The code should be:

void main(void)
{
      XmlTextReader^ reader = gcnew XmlTextReader ("books.xml");
       reader->Read() ;   // read the file
       cout << reader->Value;  
}

But no matter, the cout still doesn't compile.  If I change the #include to <iostream.h>  the build says it can't fine iostream.h. At std::cout doesn't work either.

"reader" here is an XmlTextReader object frm .NET  that reads the next node of the xml file "books.xml."

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 65

Accepted Solution

by:
rockiroads earned 1500 total points
ID: 33751206
since cout is in the standard namespace, what if you included that?

so if you added

using namespace std;


after the includes, does it make a difference?
0
 

Author Comment

by:steva
ID: 33751361
Nope.  Putting
                         
using namespace std;

after the includes doesn't make any difference.  cout is still an "undeclared identifier."
0
 

Author Comment

by:steva
ID: 33751412
Ah!  Got it.

cout requires the two statements

#include <iostream>
using namespace std;

But even then I can't write

                     cout << reader->Value;

because the thing in the .NET reader->Value  is not a string.

After adding

#include <iostream>
using namespace std;

and changing that line to

                   cout << "A string";

I compile ok.  So I'm still not sure how to display what's in reader->Value but at least the build problem is solved.  Thanks for your help.  I gave you the points for working with me on it.

0
 

Author Closing Comment

by:steva
ID: 33751421
Solved it myself, though the dialog with rockiroads was helpful.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33754965
Hi Steva. Went to bed soon after last posting.

So what did you do when you solved it. Did you assign reader->value to a string variable then outputted that variable?
0
 

Author Comment

by:steva
ID: 33755308
The magic combination to get cout to be recognized was

#include <iostream>
using namespace std;

or

#include <iostream>

std::cout

iostream.h doesn't work.

But even after that the combination of cout and reader->Value didn't work because the .NET reader->Read() function put something into reader.Value that wasn't compatible with the type of string that cout was expecting. I ended up using String^ s = reader.Value.

By the way, I posted two more questions on .NET and Visual Studio Express at

http://www.experts-exchange.com/Microsoft/Development/Visual_Studio_Express/Q_26497579.html

and

http://www.experts-exchange.com/Microsoft/Development/Visual_Studio_Express/Q_26496756.html

if you have time and feel like looking at them.

Steve


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

762 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