Ubuntu - 没有这样的文件或目录 #include <string>
Ubuntu - No such file or directory #include <string>
我正在尝试编写这样的代码:(未完成)
#include"header.h"
#include<stdlib>
#include<stdio.h>
#include<libpq-fe.h>
#include<string>
int main(){
std::string pguser = "XYZ";
std::string pgpassword = "XYZ";
std::string pghost="XYZ";
std::string pgdbname = "XYZ";
int i;
PGconn *conn;
PGresult *res;
connstr = "user=";
connstr += pguser;
connstr +="password=";
connstr += pgpassword;
connstr +="host=";
connstr += pghost;
connstr +="dbname=";
connstr += pgdbname;
//DB-Login
conn = db_login(const string &user, const string &password, const string &host, const string &dbname);
if(conn == true){
printf("LOGIN SUCCESFULLY");
}else{
printf("LOGIN FAILED");
}
return 0;
}
我的标题
#ifndef DB_H
#define DB_H
#include <string>
using namespace std;
int db_login(const string &user, const string &password, const string &host, const string &dbname);
#endif
我只是想测试它(sudo gcc main.c header.h -o测试)我得到的结果是:没有这样的文件或目录#include string
我搜索了一个解决方案并尝试了解决方案,但是我遇到了相同的错误。(也安装了 -> sudo apt-get安装构建本)
请帮助
您正在编写C 代码,但试图将其编译为C -gcc
是C语言前端,因此请改用g++
。还将您的源文件从.c
重命名为.cpp
,以从make(1)
获得自动支持。
#include<string>
是C 标头。您在.c文件中使用C 代码,这是不正确的。可能您应该将main.c重命名为main.cpp并使用G 而不是GCC
对于那些遇到这个问题并使用make而不是明确调用gcc的人:
make VERBOSE=1
将指示其GCC还是G
相关文章:
- 既然存在危险,为什么项目要使用-I include开关
- 有充分的理由在h文件中使用include保护而不是cpp文件吗
- 如何将更多文件夹添加到c++include路径
- 什么是"#include <boost/functional/hash.hpp> "?
- EASTL矢量<向量<int>>连续的
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- C++包含来自 #include "DevEngine/Core.h" 的错误
- <filesystem> 在 clang 6 和 10 上 #include 错误
- 在 void 函数中使用 #include 变量C++
- N-API include an .so or dll
- 允许哪些令牌作为 #include 的参数?
- GCC 包含标头(使用"-include")CMake 未检测到的更改
- WebAssembly include OpenCV
- 如何在 c++ 中正确指定 #include 路径以使程序可移植
- 修改生成文件以简化框架 #include 路径
- VS2015/VC++ 在新类模板中禁用默认 #include "stdafx.h"
- macOS 致命错误:sys/_types/_int8_t.h:没有此类文件或目录 #include < sys/_types/_int8_t.h>
- #include < conio.h> 和 getch() 方法之间的关系是什么?
- 如何将构建的C++库安装到 /usr/include?
- opencv 2.4.7在iOS错误背景_segm.hpp #include&lt; list&gt;未找到