c++ - 全局函数头和实现

标签 c++

如何划分全局函数的头部和实现?

我的方法是:

拆分.h

#pragma once

#include <string>
#include <vector>
#include <functional>
#include <iostream>

void split(const string s, const string c);

拆分.cpp

#include "split.h"

void split(const string& s, const string& c){
...
} 

主要.cpp

// main.cpp : Defines the entry point for the console application.
//
#include <string>
#include <vector>
#include <functional>
#include <iostream>

#include "stdafx.h"

#include "split.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    vector<string> v;
    string s = "The;;woraaald;;is;;not;;enoaaaugh";
    string c = " aaa ;; ccc";
    split(s,c);

    return 0;
}

错误是:

错误 1 ​​错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int ...\split.h 8

错误 2 错误 C2146:语法错误:在标识符“s”之前缺少“,”...\split.h 8

我该如何解决这个问题?谢谢

最佳答案

在头文件中使用 std::命名空间限定符 - std::string

关于c++ - 全局函数头和实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2367395/

相关文章:

c++ - Accelerated C++ exercise 8-5 解不清楚

c++ - 函数原型(prototype)与 C++ 类中的任何原型(prototype)都不匹配

c++ - QToolBar 子列表总是在增长。 Qt内存泄漏?

java - 系统开发生命周期和项目生命周期有什么区别?

C++ 平面数组与多维数组内存占用

c++ - 如何在 C++ 中将字符串分配/关联到二维 Int 数组

c++ - 强制第 3 方 DirectShow 过滤器使用自定义分配器

c++ - 有没有一种智能的方法可以在编译时知道要链接到的库的名称? (Linux/库本图)

c++ - 不可预测的输出

c++ - 为 apache 编写基于 C++11 线程的模块