Re: "`cout' undeclared" despite #include <iostream>

From: Otto Schaile <Otto.Schaile_at_Physik.uni-muenchen.de>
Date: Tue, 14 Mar 2006 16:47:11 +0100


Hi Vassili,
you either have to set the namespace between #include and your code: namespace std {} using namespace std;

or you have set the scope explicitly:
std::cout etc.
Cheers
Otto

Vassili Maroussov wrote:
> Dear ROOTers,
>
> I cannot compile the file in the attachment, although the <iostream> is
> included:
>
> ----------------------------
> [pcmspur5] ~/TreePlay > g++ -c count_trees.cxx -I`root-config --incdir`
> count_trees.cxx: In function `int count_trees(const char*)':
> count_trees.cxx:20: `cerr' undeclared (first use this function)
> count_trees.cxx:20: (Each undeclared identifier is reported only once
> for each
> function it appears in.)
> count_trees.cxx:20: `endl' undeclared (first use this function)
> count_trees.cxx:45: `cout' undeclared (first use this function)
> [pcmspur5] ~/TreePlay >
> ----------------------------
>
> What may be a reason for that? I use ROOT 5.06 and gcc 3.2.3 (Red Hat
> Linux 3.2.3-53)
>
> Regards,
>
> Vassili.
>
>
> ------------------------------------------------------------------------
>
> #include <iostream>
>
> #include <Ttypes.h>
> #include <TSystem.h>
> #include <TFile.h>
> #include <TTree.h>
> #include <TKey.h>
>
> #include <libgen.h> //to use basename(char *)
>
> int count_trees(const char *file0)
> {
> //Counts number of object inherited from TTree in file0 and
> //reports number of objects of unknown type
>
> char *file = gSystem->ExpandPathName(file0);
>
> TFile f(file, "READ");
> if (f.IsZombie()) {
> cerr << "ERROR (count_trees): cannot open " << file << endl;
> return -1;
> }
>
> TList *li = f.GetListOfKeys();
> TKey *key;
> TClass *cl = 0;
> TIter next(li);
>
> Int_t ntrees = 0;
> Int_t nunknowns = 0;
>
> while ((key = (TKey*)next())) {
> cl = gROOT->GetClass(key->GetClassName());
>
> // the case of unknown object
> if (!cl) {
> nunknowns++;
> continue;
> }
> // the case of tree
> if (cl->InheritsFrom(TTree::Class())) {
> ntrees++;
> }
> }
> cout << file << " : "
> << ntrees << " trees, "
> << nunknowns << " unknown objects." << endl;
>
> return 0;
> }
>
> void usage_help(char *pname)
> {
> cout << "\n\"" << basename(pname) << "\" counts number of TTrees\n";
> cout << "and unknown objects in the input_file\n\n";
> cout << "Usage:\n\t" << basename(pname) << " input_file" << endl;
> }
>
> int main(int argc, char *argv[])
> {
> if (argc != 2) {
> usage_help(argv[0]);
> return -1;
> }
>
> count_trees(argv[1]);
> return 0;
> }

-- 
Dr. Otto Schaile            Department f"ur Physik, LMU M"unchen
Phone: +49 89 289 14070     Am Coulombwall 1, D-85748 Garching, Germany
Mobil: +49 160 1553598
FAX:   +49 89 289 14072     EMail: Otto.Schaile_at_Physik.Uni-Muenchen.DE
Received on Tue Mar 14 2006 - 16:47:17 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:57 MET