分成以上三个文件,VS中是可以运行的,不知道为什么G++编译就出错了
stonewt.h:19:9: error: ‘ostream’ in namespace ‘std’ does not name a type
friend std::ostream & operator<<(std::ostream &io,Stonewt &t);
^
stonewt.h: In function ‘Stonewt operator+(double, const Stonewt&)’:
stonewt.h:22:3: error: ‘cout’ is not a member of ‘std’
std::cout<<"调用友元函数"<<std::endl;
^
stonewt.h:22:36: error: ‘endl’ is not a member of ‘std’
std::cout<<"调用友元函数"<<std::endl;
^
main.cpp: In function ‘int main()’:
main.cpp:18:16: error: ‘system’ was not declared in this scope
system("pause");
^
zyf@ubuntu:~/Desktop/test$ g++ stonewt.h stone1.cpp main.cpp
stonewt.h:19:9: error: ‘ostream’ in namespace ‘std’ does not name a type
friend std::ostream & operator<<(std::ostream &io,Stonewt &t);
^
stonewt.h: In function ‘Stonewt operator+(double, const Stonewt&)’:
stonewt.h:22:3: error: ‘cout’ is not a member of ‘std’
std::cout<<"调用友元函数"<<std::endl;
^
stonewt.h:22:36: error: ‘endl’ is not a member of ‘std’
std::cout<<"调用友元函数"<<std::endl;
^
zyf@ubuntu:~/Desktop/test$ g++ stonewt.h
stonewt.h:19:9: error: ‘ostream’ in namespace ‘std’ does not name a type
friend std::ostream & operator<<(std::ostream &io,Stonewt &t);
^
stonewt.h: In function ‘Stonewt operator+(double, const Stonewt&)’:
stonewt.h:22:3: error: ‘cout’ is not a member of ‘std’
std::cout<<"调用友元函数"<<std::endl;
^
stonewt.h:22:36: error: ‘endl’ is not a member of ‘std’
std::cout<<"调用友元函数"<<std::endl;
^
zyf@ubuntu:~/Desktop/test$ clear
zyf@ubuntu:~/Desktop/test$ g++ stonewt.h
stonewt.h:19:9: error: ‘ostream’ in namespace ‘std’ does not name a type
friend std::ostream & operator<<(std::ostream &io,Stonewt &t);
^
stonewt.h: In function ‘Stonewt operator+(double, const Stonewt&)’:
stonewt.h:22:3: error: ‘cout’ is not a member of ‘std’
std::cout<<"调用友元函数"<<std::endl;
^
stonewt.h:22:36: error: ‘endl’ is not a member of ‘std’
std::cout<<"调用友元函数"<<std::endl;
^
zyf@ubuntu:~/Desktop/test$ g++ -i stonewt.h
g++: error: unrecognized command line option ‘-i’
zyf@ubuntu:~/Desktop/test$ g++ stonewt.h stone1.cpp main.cpp
stonewt.h:19:9: error: ‘ostream’ in namespace ‘std’ does not name a type
friend std::ostream & operator<<(std::ostream &io,Stonewt &t);
^
stonewt.h: In function ‘Stonewt operator+(double, const Stonewt&)’:
stonewt.h:22:3: error: ‘cout’ is not a member of ‘std’
std::cout<<"调用友元函数"<<std::endl;
^
stonewt.h:22:36: error: ‘endl’ is not a member of ‘std’
std::cout<<"调用友元函数"<<std::endl;