C++ 将字符串发送到其他文件c++;
如何将字符串变量发送到其他文件中的函数中? main.cpp:C++ 将字符串发送到其他文件c++;,c++,C++,如何将字符串变量发送到其他文件中的函数中? main.cpp: #include <iostream> #include <conio.h> #include <string> #include "headers.hpp" using namespace std; int main() { string a; cout<<"Type:"<<endl; cin>>a; other(a);
#include <iostream>
#include <conio.h>
#include <string>
#include "headers.hpp"
using namespace std;
int main()
{
string a;
cout<<"Type:"<<endl;
cin>>a;
other(a);
getch();
return( 0 );
}
function.cpp:
#include "headers.hpp"
#include <iostream>
#include <math.h>
using namespace std;
void other(string a){
cout<<a;}
#包括“headers.hpp”
#包括
#包括
使用名称空间std;
无效其他(字符串a){
cout如果您说它没有编译,您必须将#include
从main.cpp移动到headers.hpp您想要一个解决方案,但问题到底是什么?“它不起作用”没有真正说明这个问题。好吧,看看我的玻璃球,我发现它不起作用,因为headers.cpp和function.cpp include都不起作用。错误:'string'没有在这个范围内声明,或者用'std::string'替换'string',或者使用命名空间std;'将行从function.cpp移到headers.hpp
#include "headers.hpp"
#include <iostream>
#include <math.h>
using namespace std;
void other(string a){
cout<<a;}