g++编译错误.h文件

g++ compile error .h file

本文关键字:文件 错误 编译 g++      更新时间:2023-10-16

我试图在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 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"

#include "filename"用于本地头文件,由您制作。

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

没有<"filename">这样的语法

#include <"writeVector.h"

该代码无效。下面任意一行都可以:

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

,但后者保留给system标头。