将字符串发送到其他c++文件中的函数

sent string into function in other files c++

本文关键字:文件 函数 c++ 其他 字符串      更新时间:2023-10-16

如何将字符串变量发送到其他文件中的函数?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);
    getch();    
    return( 0 );
}

headers.hpp:

#ifndef HEADERS_HPP
#define HEADERS_HPP
void other(string a);
#endif

function.cpp:

#include "headers.hpp"
#include <iostream>
#include <math.h>
using namespace std;
void other(string a){
     cout<<a;}

我不知道为什么它不工作。你知道解决方法吗?

如果你说它不能编译,你必须把#include <string>main.cpp移到headers.hpp