Solved

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

Posted on 2010-09-23
9
656 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

19 Experts available now in Live!

Get 1:1 Help Now