g++编译错误.h文件
我正在尝试在 Linux Ubuntu 10.10 中使用 g++ 编译 .cpp 文件,当我尝试编译此代码时,
#include <iostream>
#include <vector>
#include <"writeVector.h"
#include <"insertionSort.h">
using namespace std;
int main()
{
int n;
int i;
vector<int> V;
cout << "Enter the amount of numbers you want to evaluate: ";
cin >> n;
cout << "Enter your numbers to be evaluated: " << endl;
while (V.size() < n && cin >> i){
V.push_back(i);
}
InsertionSort(V);
write_vector(V);
return 0;
}
我在同一文件夹中拥有两个 .h 文件,但它一直说我的 writeVector.h
文件或文件夹不存在。
这就是我的 writeVector.h
文件的样子
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
void write_vector(const vector<T>& V)
{
cout << "The numbers in the vector are: " << endl;
for(int i=0; i < V.size(); i++)
cout << V[i] << " ";
}
insertionSort.h
文件
#include <iostream>
#include <vector>
using namespace std;
void InsertionSort(vector<int> &num)
{
int i, j, key, numLength = num.length( );
for(j = 1; j < numLength; j++) // Start with 1 (not 0)
{
key = num[j];
for(i = j - 1; (i >= 0) && (num[i] < key); i--) // Smaller values move up
{
num[i+1] = num[i];
}
num[i+1] = key; //Put key into its proper location
}
return;
}
I'm trying to compile a .cpp file using g++ in Linux Ubuntu 10.10 and when i try to compile this code
#include <iostream>
#include <vector>
#include <"writeVector.h"
#include <"insertionSort.h">
using namespace std;
int main()
{
int n;
int i;
vector<int> V;
cout << "Enter the amount of numbers you want to evaluate: ";
cin >> n;
cout << "Enter your numbers to be evaluated: " << endl;
while (V.size() < n && cin >> i){
V.push_back(i);
}
InsertionSort(V);
write_vector(V);
return 0;
}
I have both .h files in the same folder but it keeps saying that my writeVector.h
file or folder does not exist.
This is what my writeVector.h
file looks like
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
void write_vector(const vector<T>& V)
{
cout << "The numbers in the vector are: " << endl;
for(int i=0; i < V.size(); i++)
cout << V[i] << " ";
}
insertionSort.h
file
#include <iostream>
#include <vector>
using namespace std;
void InsertionSort(vector<int> &num)
{
int i, j, key, numLength = num.length( );
for(j = 1; j < numLength; j++) // Start with 1 (not 0)
{
key = num[j];
for(i = j - 1; (i >= 0) && (num[i] < key); i--) // Smaller values move up
{
num[i+1] = num[i];
}
num[i+1] = key; //Put key into its proper location
}
return;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改
为
#include "filename"
用于您创建的本地头文件。#include
用于头文件 全局包含在 C++ 中,系统头文件没有类似
<"filename">
的语法Change
to
#include "filename"
is used for local header files, which are made by you.#include <filename>
is used for header files Globally included in C++, System header filesthere is no syntax like
<"filename">
该代码无效。下面的任何一行都可以工作:
但后者是为系统标头保留的。
That code is not valid. Either of the below lines would work:
but the latter is reserved for system headers.