2013-04-24 2 views
0

여러 파일로 프로그램을 만들고 있는데 tout 파일에 < <을 인식하지 못합니다. 누구든지 문제가있는 곳을 찾을 수 있습니까? 다른 오류 중에서도이 노드에있는 "cout이이 범위에서 선언되지 않았습니다."오류가 발생합니다. 내 주요 기능 :내 프로그램에서 cout <<을 인식하지 못합니까?

#include <iostream> 
#include "bst.h" 
using namespace std; 



int main(int argc, char *argv[]) { 
    cout<<"hi"; 
    bst *list = new bst(); 
    return 0; 
} 

내 BinarySearchTree 파일 :

#ifndef bst_H 
#define bst_H 
#include <iostream> 
#include <string> 
#include "tnode.h" 



class bst 
{ 
    public: 

    bst() 
    { 
    root = NULL; 
    } 
void add(int key, char value) { 
     if (root == NULL) { 
      root = new tnode(key, value); 
      return 
     } else 
      root->add(key, value); 
      return 
} 






tnode *root; 

}; 

#endif 

내 노드 파일 :

#ifndef tnode_H 
#define tnode_H 
#include <iostream> 
#include <string> 

class tnode 
{ 
public: 
    tnode(int key, char value) 
    { 
       this->key = key; 
       this->value = value; 
       N = 1; 
       left = NULL; 
       right = NULL; 
       cout<<"hi"; 
    } 

void add(int key, char value) { 
     if (key == this->key) 
     { 
      cout<<"This key already exists"; 
      return; 
     } 
     else if (key < this->key) 
     { 
      if (left == NULL) 
      { 
        left = new tnode(key, value); 
        cout<<"Your node has been placed!!"; 
        return; 
      } 
      else 
      { 
        left->add(key, value); 
        cout<<"Your node has been placed!"; 
        return; 
      } 
     } 
     else if (key > this->key) 
     { 
      if (right == NULL) 
      { 
        right = new tnode(key, value); 
        cout<<"Your node has been placed!!"; return; 
      } 
      else 
        return right->add(key, value); 
     } 
     return; 
} 
     tnode* left; 
     tnode* right; 
     int key; 
     char value; 
     int N; 

}; 




#endif 

답변

2

당신은 네임 스페이스 std를 사용해야합니다. using namespace std (.cpp 파일에는 없지만 .h 파일에는 들어갈 수 없으므로 here에 대한 자세한 내용은 std::cout을 참조하십시오.) 당신이 더 나은 두 번째 방법을 사용하는 것, 그래서

using namespace std; 

또는 tnode 파일

그러나 using namespace std에서

std::cout 

나쁜 연습 간주됩니다 :

4

당신은 할 필요가

std::cout<<"Your node has been placed!!"; 
관련 문제