[英]Ubuntu - No such file or directory #include <string>
i am trying to write a code like this: (not finished)我正在尝试编写这样的代码:(未完成)
#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;
}
My Header.h我的标题.h
#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
I just wanted to test it (sudo gcc main.c header.h -o test) The Result i get is : No such file or directory #include string我只是想测试它(sudo gcc main.c header.h -o test)我得到的结果是:没有这样的文件或目录#include string
I searched for an solution and tried it out but i get the same error.我搜索了一个解决方案并尝试了它,但我得到了同样的错误。 (also installed -> sudo apt-get install build-essential )
(也已安装 -> sudo apt-get install build-essential )
Please Help请帮忙
You are writing C++ code, but trying to compile it as C - gcc
is the C language front-end, so use g++
instead.您正在编写 C++ 代码,但尝试将其编译为 C -
gcc
是 C 语言前端,因此请改用g++
。 Also rename your source files from .c
to .cpp
to get automatic support from make(1)
.还将您的源文件从
.c
重命名为.cpp
以获得来自make(1)
自动支持。
#include<string>
is C++ header. #include<string>
是 C++ 头文件。 You are using C++ code in .c file, it is incorrect.您在 .c 文件中使用 C++ 代码,这是不正确的。 Probably you should rename main.c to main.cpp and use g++ instead of gcc
可能您应该将 main.c 重命名为 main.cpp 并使用 g++ 而不是 gcc
For those who run into this question and use make instead of explicitly call gcc:对于那些遇到这个问题并使用 make 而不是明确调用 gcc 的人:
make VERBOSE=1
will indicate whether its gcc or g++将指示它是 gcc 还是 g++
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.