在我的程序中不认识 cout<<?

Not recognizing cout<< in my program?

本文关键字:lt cout 不认识 我的 程序      更新时间:2023-10-16

我正在创建一个包含多个文件的程序,它不识别cout<<在我的tnode文件中。谁能找到问题所在吗?在其他错误中,我在我的节点文件中得到这个错误"未在此范围内声明cout"。我的主要功能:

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

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

My BinarySearchTree file:

#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

你需要做的是:

  using namespace std;

  std::cout 

tnode文件

但是using namespace std被认为是不好的做法,所以您最好使用第二种方式:

std::cout<<"Your node has been placed!!";

需要使用命名空间"std"。通过using namespace std(它可以进入。cpp文件,但永远不会进入。h文件,在这里了解更多原因)或在调用它时使用std::cout