在我的程序中不认识 cout<<?
Not recognizing cout<< in my program?
我正在创建一个包含多个文件的程序,它不识别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
。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- std::cout.imbue()多重调用
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- 为什么我应该在异常处理中使用std::cerr而不是std::cout
- 在作为静态成员包含在另一个类中的类的构造函数中使用 cout
- 在 COUT 语句中使用 COUT 调用函数
- GCC 4.8.2 自动矢量化由于 cout 而失败
- std::cout输出int时出现编译错误
- 为什么COUT在朋友函数中不起作用,该功能超载了操作员&lt;&lt;这是一个iStream运算符
- C++标准::cout和<<操作员,优先级
- 以x的倍数填充前导零,使用std::cout<<std::十六进制
- 错误:没有匹配'运算符<<"在'std::cout
- 过载<<比如cout错误
- cout & lt; & lt;“text"只在部分时间显示
- 如何显示/打印字符串对象?cout & lt; & lt;Int工作,count <<字符串
- 我怎样才能到达cout<<"排序:";;当C++中没有输入数字时