iostream and #include question

I'm trying to compile the following code, where I include the boost graph library

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#include <boost/graph/graphviz.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <string>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <boost/graph/iteration_macros.hpp>


   int main(int,char*[])
   {
      typedef std::pair<int,int> Edge;
      Edge used_by[] = { Edge(1, 5), Edge(1, 7), Edge(1, 2), Edge(2, 7), Edge(2, 12), Edge(3, 7), 
	  Edge(3, 10), Edge(3, 12), Edge(4, 5), Edge(5, 6),Edge(6, 9),Edge(7, 8), Edge(8, 9),Edge(9, 14),
	  Edge(10, 11), Edge(11, 14),Edge(12, 13),Edge(13, 14),Edge(14, 15) };
      const int nedges = sizeof(used_by)/sizeof(Edge);
      double weights[nedges];
      std::fill(weights, weights + nedges, 1.0);
      weights[1] = 0.5;
      weights[2] = 1.5;
      weights[3] = 2.5;
  
      using namespace boost;
      typedef adjacency_list< vecS, vecS, directedS, property< vertex_color_t, default_color_type >, property< edge_weight_t, double > > Graph;
      Graph g_write(used_by, used_by + nedges, weights, 16);
	  
      // write
    /*  dynamic_properties dp;
      dp.property("weight", get(edge_weight, g_write));
      dp.property("node_id", get(vertex_index, g_write));
      std::ofstream ofs( "test.dot" );
      write_graphviz(ofs, g_write, dp); */
	  cout << "Means, so far, this return was successful" << endl;
      return 0;
  }


Unfortunately I get the following errors


1>------ Build started: Project: CompundDataTypes, Configuration: Debug Win32 ------
1>Compiling...
1>BoostGraph_Display_1.cpp
1>h:\c++\compund data types\compunddatatypes\boostgraph_display_1.cpp(34) : error C2065: 'cout' : undeclared identifier
1>h:\c++\compund data types\compunddatatypes\boostgraph_display_1.cpp(34) : error C2065: 'endl' : undeclared identifier
1>Build log was saved at "file://h:\C++\Compund DAta types\CompundDataTypes\Debug\BuildLog.htm"
1>CompundDataTypes - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



I have two questions.

1) Why is it not recognizing cout in the program. I have included the iostream library on top?

2) I'm using boost which is an external library. When I tried compiling with the statement #include <boost/graph> or #include <boost/graph/> . The program didn't work. Would anyone how can I include all the classes/methods in boost/graph? e.g. in Java, all I had to do was ... boost/graph/*; */

Any help is appreciated.
1) cout and endl are declared under std namespace To fix the problem, you can simply add this line to your source code:
usign namespace std;
or
using std::cout;
or use :: operator:
 
std::cout <<"blah blah"<<std::endl;

Concerning the problem with boost, would you post the errors that you get when including boost?
@Null :- Thanks a lot. That was a silly error, but I guess such is the process of learning a new programming language.

@magnificence7 : - Sure. Please see the output below

 1>------ Build started: Project: CompundDataTypes, Configuration: Debug Win32 ------
1>Compiling...
1>BoostGraph_Display_1.cpp
1>h:\c++\compund data types\compunddatatypes\boostgraph_display_1.cpp(9) : fatal error C1083: Cannot open include file: 'boost/graph': No such file or directory
1>Build log was saved at "file://h:\C++\Compund DAta types\CompundDataTypes\Debug\BuildLog.htm"
1>CompundDataTypes - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



I get this error whenever I use #include <boost/graph> , #include <boost/graph/> , or #include <boost/graph/*> */


Note that in the above program, I have already included elements from boost's graph library.

1
2
3
 
#include <boost/graph/graphviz.hpp>
#include <boost/graph/adjacency_list.hpp> 
It sounds like boost/graph isn't in any of the default locations your compiler searches.

-Albatross
Topic archived. No new replies allowed.