2014-09-19 72 views
-1

我得到一個奇怪的C3681錯誤,一直說不能找到我的一個函數的標識符。我非常困惑,並嘗試使用Google時找到的解決方案,但我無法解決問題。我寧願不使用stl。在C++中獲取構建錯誤

錯誤:

錯誤1個錯誤C3861: 'readTheStuff':標識符沒有發現C:\用戶\ XXXXXX \桌面\數據結構\ homework2 \ homework2 \ editor.cpp 38 1 Homework2

#include <iostream> 
#include <fstream> 
#include <string> 

using namespace std; 
int readFile(const char *fileName) { 
    ifstream myReadFile; 
    string line; 
    int i = 0; 
    myReadFile.open(fileName); 
    if (myReadFile.is_open()) { 
     while (!myReadFile.eof()) { 
      getline(myReadFile, line); 
      line += " "; //adds a space after every line 
      //cout << line << endl; 
      readTheStuff(line); 
     } 
    } 
    myReadFile.close(); 
    return 0; 
} 

void readTheStuff(string command){ 
    cout << command; //testing 
} 

int main(int argc, const char* argv[]){ //when they call, going to pass two parameters 
    if (argc > 2){ 
     cout << "Error, more than one file given" << endl; 
    } 
    else if (argc < 2){ 
     cout << "Error, no file given" << endl; 
    } 
    else if (argc == 2){ 
     readFile(argv[1]); 
    } 
} 

回答

4

你必須先聲明一個函數,然後才能調用它。要麼在readFile之前聲明readTheStuff,或者更簡單地說,只是將整個函數向上移動readFile

0

2種解決方法。 1)包括以下行正下方的editor.cpp

無效readTheStuff(的std :: string命令)

您#包括或包括除了下面一行到其他的#includes

#include "editor.h" 

內editor.h以下行需要出現

void readTheStuff(string command) 

這就是所謂的原型和允許編譯器裏nk readTheStuff(line)實際功能reaTheStuff(string command).