test2.h:5:17: error: ‘string’ is not a member of ‘std’ aries@ubuntu:~/aries/Makefile/Demo$ g++ -o main main.cpp In file included from main.cpp:1:0: test1.h:5:17: error: variable or field ‘test1_cout’ declared void test1.h:5:17: error: ‘string’ was not declared in this scope In file included from main.cpp:2:0: test2.h:5:17: error: variable or field ‘test2_cout’ declared void test2.h:5:17: error: ‘string’ was not declared in this scope aries@ubuntu:~/aries/Makefile/Demo$
#ifndef _ERROR_1_ #define _ERROR_1_ #include<cstring> void cout_1(string a1); #endif
#include<error.h> #include<iostream> using namespace std; void cout_1(string str) { cout << str<< endl; } int main() { cout_1("test"); return 0; }
aries@ubuntu:~/aries/Makefile/Demo$ g++ -o error error.cpp aries@ubuntu:~/aries/Makefile/Demo$ ./error test
#include<error.h> void cout_1(string str) { cout << str<< endl; }
#include"error.h" #include"error_h.cpp" #include<iostream> using namespace std; int main() { cout_1("test"); return 0; }
aries@ubuntu:~/aries/Makefile/Demo$ g++ -o error error.cpp In file included from error.cpp:1:0: error.h:5:13: error: variable or field ‘cout_1’ declared void error.h:5:13: error: ‘string’ was not declared in this scope In file included from error.cpp:2:0: error_h.cpp:3:13: error: variable or field ‘cout_1’ declared void error_h.cpp:3:13: error: ‘string’ was not declared in this scope error.cpp: In function ‘int main()’: error.cpp:9:15: error: ‘cout_1’ was not declared in this scope
#include<error.h> #include<cstring> #include<iostream> using namespace std; void cout_1(string str) { cout << str<< endl; }
aries@ubuntu:~/aries/Makefile/Demo$ g++ -o error error.cpp In file included from error.cpp:1:0: error.h:5:13: error: variable or field ‘cout_1’ declared void error.h:5:13: error: ‘string’ was not declared in this scope
原文:http://blog.csdn.net/laoniu_c/article/details/19847843