Solved

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

Posted on 2010-09-23
9
660 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
  • 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
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

939 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

10 Experts available now in Live!

Get 1:1 Help Now