g ++编译错误.h文件 [英] g++ compile error .h file

查看:141
本文介绍了g ++编译错误.h文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Linux Ubuntu 10.10中使用g ++编译一个.cpp文件,当我尝试编译这个代码时。

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;                                                                     
}   

我在同一个文件夹中有两个.h文件, writeVector.h 文件或文件夹不存在。

I have both .h files in the same folder but it keeps saying that my writeVector.h file or folder does not exist.

这是我的 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 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;                                                                    
}


推荐答案

更改

#include <"writeVector.h"                                                       
#include <"insertionSort.h">  

#include "writeVector.h"                                                       
#include "insertionSort.h"

#includefilename用于由您创建的本地头文件。

#include "filename" is used for local header files, which are made by you.

#include< filename> 用于头文件全局包含在C ++中,系统头文件

#include <filename> is used for header files Globally included in C++, System header files

code><filename>

there is no syntax like <"filename">

这篇关于g ++编译错误.h文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆