Solved

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

Posted on 2010-09-23
9
670 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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
 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.Net Loading Word 11 109
DB Mail Export to Excel some row wrap to new row 30 142
Problem to DocumentFormat 8 145
How can i Install a new Data Source on Visual Studio 2 120
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 …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

739 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