Hi guys,
I have a code in C++ that was written way back in 1995.Back then,I guess even in C++,#include<iostream.h> was used unlike nowadays, #include<iostream> using namespace std;.....im rite now trying to compile that code with a g++ compiler.It gives the error at lots of places:"cout not declared in this scope"....I have tried using namespace std.....but if I use that then errors sprout up in files that belong to C++ standard library.....so I haven't been able to use using namespace std;.......i have even tried using std::cout<<......<<std::endl.....but even that is not working..........any ideas to get past this problem are appreciated.

Thanks........

post one of the files that has the errors, especially the top of the *.cpp file where you have all the includes etc. The problem is most likely missing something like this:

#include <iostream>
using std::cout;

or this

#include <iostream>
using  namespace std; // Not recommended

or like this:

#include <iostream>

int main()
{
   std::cout << "Hello World\n";
}
/********************************************************************/
/*                                                                  */
/*  parse (...) :                                                   */
/*       1. Reads the graph problem in extended DIMACS format.      */
/*       2. Prepares internal data representation                   */
/*                                                                  */
/*  Requires Routines:                                              */
/*       1. readProblemLine                                         */
/*       2. readNodeDescription                                     */
/*       3. readArcDescription                                      */
/*                                                                  */
/********************************************************************/
       
// Files to be included:
#include <iostream.h>
using std::cout;
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

//#ifdef NO_ERROR_HANDLING
//#define throw(string)  {cerr << string << "\n"; exit(1);}
//#define try
//#endif

inline void swap(arc *e1, arc *e2)
{
  arc temp = *e1;
  *e1 = *e2;
  *e2 = temp;
#ifdef REVERSE_POINTER
  if (e1->reverseArc() != e1)
    {
      e1->reverseArc()->setReverse(e1);
      e2->reverseArc()->setReverse(e2);
    }
  else 
    {
      e1->setReverse(e2);
      e2->setReverse(e1);
    }
#endif
}

void parse()
{
  long   *arc_tail=NULL;          // Internal Array: tails of the arcs
  long   *arc_first=NULL;         /* Internal Array for holding:
                                     - node degree
                                     - position of the first outgoing arc */
  long   tail;                    // Tail of current arc

  long   arc_num;
  long   arc_new_num;
//  DistType   max_cost = 0;

  arc    *arc_current=NULL;       // Pointer to the arc structure
  arc    *arc_new;
  node   *v; 

  long    no_lines=0;             // # of current input line
  long    no_plines=0;            // # of problem-lines
  long    no_nlines=0;            // # of node(source)-lines
  long    no_alines=0;            // # of arc-lines

  char    input_line[MAXLINE];    // For reading input line

/* The main loop:
        -  reads the line of the input,
        -  analises its type,
        -  checks correctness of parameters,
        -  puts data to the arrays,
        -  does service functions
*/
  try{
    while ( gets ( input_line ) != NULL ) {
      no_lines ++;

      switch (input_line[0]) 
	{
	case 'c':                       // Skip lines with comments
	case '\n':                      // Skip empty lines   
	case '\0':                      // Skip empty lines at the end of file
	case 't':                       // Name of the problem
	  break;
	    
	case 'p':                       // Problem description     
	  if ( no_plines > 0 ) throw("more than one problem line");                         //CHANGE MADE BY AMULYA YADAV.....JUST TO CHECK 
	  no_plines = 1;
   
	  readProblemLine(G,input_line);

	  arc_tail = new long[G.numArcs()]; 
	  arc_first= new long[G.numNodes()+1];
	  for (long i=0; i<G.numNodes()+1; i++) arc_first[i]=0;

	  if ( arc_first == NULL || arc_tail == NULL )
	    throw("can't obtain enough memory to solve this problem");
		     
	  arc_current = G.firstArc();	    // Setting pointer to the current arc
	  break;
	
	case 'n':		               // Node description
	  if ( no_plines == 0 ) throw("problem description must come first");
	  if ( no_nlines > MAX_NODE_LINES) throw("too many nodes in the input");

	  no_nlines++;   
	  readNodeDescription(G,input_line);
	  break;

	
	case 'a':                    // Arc Description
	  if ( no_nlines < MIN_NODE_LINES )  throw("too few nodes lines"); 	    
	  if ( no_alines >= G.numArcs() )  throw("too many arcs input");
		
	  tail = readArcDescription(G,input_line,arc_current);
	  arc_first[tail + 1] ++; /* no of arcs outgoing from tail
                                           is stored in arc_first[tail+1] */

	  // Storing Information About The Arc
	  arc_tail[no_alines] = tail;

#ifdef REVERSE_ARCS  //Add reverse arc as well
	  tail = G.index(arc_current->head());
	  arc_current++;
	  no_alines++;
	  arc_first[tail + 1] ++;
	  arc_tail[no_alines] = tail;
#endif
	  no_alines ++;
	  arc_current ++;
	  break;

	default:
	  throw("unknown line type in the input");
	  break;
	  
	} // End of switch
    }     // End of input loop

/* ----- all is red  or  error while reading ----- */ 

    if ( feof (stdin) == 0 ) throw("reading error");

    if ( no_lines == 0 ) throw("input file is empty");

//if ( no_alines < G.numArcs() ) // Not enough arcs
//  parserError(EN19,no_lines);

#ifdef ARTIFICIAL_SOURCE
    //    G.setSource(SOURCE);

    forallNodes(v,G)  {
      if (!connectedToSource(v)) continue;

      createSourceArc(arc_current,v);  // Create reverse arc at same time
      arc_current++;

      tail =  G.getSource()->index();
      arc_first[tail + 1] ++;
      arc_tail[no_alines] = tail;
      no_alines++;
#ifdef REVERSE_ARCS      
      arc_current++;
      tail =  G.index(v);
      arc_first[tail + 1] ++;
      arc_tail[no_alines] = tail;
      no_alines++;
#endif // REVERSE_ARCS

    }
#endif // ARTIFICIAL_SOURCE

#ifdef ARTIFICIAL_SINK  
    //    G.setSink(SINK);

    forallNodes(v,G)  {
      if (!connectedToSink(v)) continue;

      createSinkArc(arc_current,v);  // Create reverse arc at same time
      arc_current++;

      tail =  G.index(v);
      arc_first[tail + 1] ++;
      arc_tail[no_alines] = tail;
      no_alines++;
#ifdef REVERSE_ARCS      
      arc_current++;
      tail =  G.getSink()->index();
      arc_first[tail + 1] ++;
      arc_tail[no_alines] = tail;
      no_alines++;
#endif // REVERSE_ARCS

    }
#endif // ARTIFICIAL_SINK

    forallNodes(v,G) {
      long indx;
      indx = G.index(v);
      if (v !=  G.firstNode())   arc_first[indx] += arc_first[indx-1];
      v->initAdjList( G.arc_i(arc_first[indx]) );
    }
    // init. sentinel
    G.node_i(G.numNodes())->initAdjList(G.arc_i(G.numArcs()));

    /*
    // setup first arcs, including sentinel node
    long indx, sum;
    sum = 0;
    for (indx = 0; indx <= G.numNodes(); indx++)
      {
	sum+=arc_first[indx];
	v = G.node_i(indx);
	v->initAdjList(G.arc_i(sum));
      }
      */
/********** ordering arcs - linear time algorithm ***********/

/* before below loop arc_first[i+1] is the number of arcs outgoing from i;
   after this loop arc_first[i] is the position of the first 
   outgoing from node i arcs after they would be ordered;
   this value is transformed to pointer and written to node.first[i]
   */


    forallNodes(v,G) {
      long indx;
      indx = G.index(v);
      // AVG      last =  G.index(v->lastOutArc());
                             /* arcs outgoing from i must be cited    
                              from position arc_first[i] to the position
                              equal to initial value of arc_first[i+1]-1  */
      arc *e;

      e = G.arc_i(arc_first[indx]);
      forallRemainingOutArcs(e,v) { 
	arc_num = G.index(e);
	tail = arc_tail[arc_num];
          /* the arc no  arc_num  is not in place because arc cited here
             must go out from indx;
             we'll put it to its place and continue this process
             until an arc in this position would go out from indx */
	while ( tail != indx ) {
	  arc_new_num  = arc_first[tail];
	  arc_new      = G.arc_i(arc_new_num);
	  swap(arc_new,e);
	  arc_tail[arc_num] = arc_tail[arc_new_num];

	  // We Increase arc_first[tail] but Label Previous Position

	  arc_tail[arc_new_num] = tail;
	  arc_first[tail] ++ ;
	  
	  tail = arc_tail[arc_num];
	}
      }
      /* all arcs outgoing from  v  are in place */
    }       

// -----------------------  Arcs Are Ordered  ------------------------- */

// Assigning Output Values

#ifdef SHORTEST_PATH
if ( G.getSource()->adjListIsEmpty() ) throw("no arc out of source");
#endif
   }
#ifndef NO_ERROR_HANDLING
catch(char *str) {
  cerr << input_line;
  cerr << "\nLine " << no_lines << " of input - " << str << "\n";
  abort();
}
#endif

// Free Internal Memory 
  delete arc_first ; 
  delete arc_tail ;

/* ---------------------------------- */

}

/* --------------------   end of parser  -------------------*/

This is the code that is problematic.Actually ,the code which I have has many files and this is one of them.It has a make file and that is what I try to run by using make install.The errors that show up are:
In file included from lds_run.cc:20:
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:99: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:105: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:106: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:114: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:115: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:136: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:144: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:146: error: ‘cout’ was not declared in this scope


These are just a part of the errors that I'm getting.If you still feel you're not sure what the problem is.you can go this link http://avglab.com/andrew/soft.html and download the the zip file named BIM...that's the code I'm trying to run.

Any help will be appreciated.
Thanks,anyway.

I tried changing the iostream.h to iostream also.I've tried out all variations that you told me about.But none of them has worked.

Thanks

what would happen if you change you include section to look like this

#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <assert.h>

using namespace std;

Enormous number of errors pop up in wchar2.h and wchar.h which are standard C++ library files and this should definitely not happen.A sample of the errors is as follows:

/usr/include/bits/wchar2.h: In function ‘wchar_t* __wmemcpy_alias(wchar_t*, const wchar_t*, size_t)’:
/usr/include/bits/wchar2.h:28: error: ‘cout’ was not declared in this scope
/usr/include/bits/wchar2.h:28: error: expected primary-expression before ‘<<’ token
/usr/include/bits/wchar2.h: In function ‘wchar_t* __wmemcpy_chk_warn(wchar_t*, const wchar_t*, size_t, size_t)’:
/usr/include/bits/wchar2.h:32: error: ‘cout’ was not declared in this scope
/usr/include/bits/wchar2.h:32: error: expected primary-expression before ‘<<’ token
/usr/include/bits/wchar2.h: At global scope:
/usr/include/bits/wchar2.h:36: error: expected ‘;’ before ‘__attribute__’
/usr/include/bits/wchar2.h:36: error: declaration does not declare anything
/usr/include/bits/wchar2.h: In function ‘wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t)’:
/usr/include/bits/wchar2.h:40: error: redefinition of ‘wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t)’
/usr/include/wchar.h:327: error: ‘wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t)’ previously defined here
/usr/include/bits/wchar2.h:40: error: ‘cout’ was not declared in this scope
/usr/include/bits/wchar2.h:40: error: expected primary-expression before ‘<<’ token

Nathan and Ancient Dragon,any help shall be appreciated...........ive already given u the link in case u want a complete understanding of the problem......
Thanks

you know, this post seems suspicious. It looks like( at lest to me) that you are
trying to get someone else's code, who wrote it a while back, to compile so you can use
it either for h.w or for some school related stuff? If you don't get what graphs are
then go study more theory and ask specific questions, otherwise good luck cheating.

--------------------
PS: forgive if I was wrong.

Dont be bitter if you dont have an answer to the questions asked.And I dont think you are important enough to tell you what am I doing with this code?..........and you know what,I'd even suggest a course in etiquettes for u.............

what compiler are you using anyway? I tried to compile it with vc++ 2010 express and had no problems using

#include <iostream>
using std::cout;
// etc. etc

The code you posted 6 hours ago contains a lot of other problems than just the one you have been complaining about, most likely because you have failed to include other critical header files. You will never get a clean compile without those header files.

Hi Ancient Dragon,
I am using GNU g++ compiler.
and yup,there are a lot of dependencies in between a lot of files so I dont compile them one by one. The scientist who had written this code had written a makefile and i use that to compile and generate the binaries.

I dont think i can post all the files here .there are more than 100 files in the source code. But if you want to get a good look, I have put in the link where you'll find the code.

Thanks for replying.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.