簡體   English   中英

g ++編譯錯誤.h文件

[英]g++ compile error .h file

我試圖在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;                                                                    
}

更改

#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>

但后者保留給系統標頭使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM