溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

求助!C++ 實踐之引入外部頭文件失敗

發(fā)布時間:2020-07-03 19:28:20 來源:網(wǎng)絡(luò) 閱讀:777 作者:洛山紅茶 欄目:編程語言

 本來想整合一下,這兩天學(xué)習(xí)的內(nèi)容,發(fā)布一個具備讀寫ini、寫日志的demo。誰想到新的問題出來,按照原思路。創(chuàng)建common.cpp 將一些工具方法歸納其中。demo1.cpp通過引入common.h文件 實現(xiàn)方法的調(diào)用。

    求助!C++ 實踐之引入外部頭文件失敗

    關(guān)鍵代碼如下:

    common.cpp:

    

/**
 * 這是一個 工具類的對象
 */#include <windows.h>#include <string.h>#define INI_FILE_PATH ".//study.ini"#define LOG_FILE_NAME "studylog"#define LOG_VALUE_MAXSIZE 80void readIniValue(char* lable,char* anchor,char* iniValue){  char buffer[LOG_VALUE_MAXSIZE];
  GetPrivateProfileString(lable, anchor, NULL, buffer, sizeof(buffer), INI_FILE_PATH );//讀取 配置文件 需要引入 <windows.h>
	iniValue = new char[sizeof(buffer)+1];	strcpy(iniValue,buffer);

}

    commom.h:

  #ifndef COMMON
  #define COMMON
  /**
   * 讀取配置文件
   * @param  label    日志文件 標(biāo)簽
   * @param  anchor   日志文件 錨點
   * @param  iniValue 讀取到日志的值
   */
   void readIniValue(char* lable,char* anchor,char* iniValue);  #endif

    demo1.cpp:

/*
這個案例 用于說明C++ 讀取配置文件 寫入日志文件
2017-08-03
 *//**
 * 這個案例 用于說明C++ 讀取配置文件 寫入日志文件
 * @param  argc [description]
 * @param  argv [description]
 * @return      [description]
 * @createTime 2017-08-03
 */
 #include "common.h"#include <iostream>#include <windows.h>// 讀取ini文件 引入 必要文件using namespace std;//定義全局變量// #define INI_FILE_PATH ".//study.ini"http:// #define LOG_FILE_NAME "studylog.txt"http:// void readIniValue(char* lable,char* anchor,char* iniValue){//   char buffer[80];//   GetPrivateProfileString(lable, anchor, NULL, buffer, sizeof(buffer), INI_FILE_PATH );//讀取 配置文件 需要引入 <windows.h>//  std::cout << buffer << '\n';////// 	iniValue = new char[sizeof(buffer)+1];// 	strcpy(iniValue,buffer);//// }int main() { // 整理 讀取 配置ini 配置文件
 // char buffer[80];
 // GetPrivateProfileString("Log", "Level", NULL, buffer, sizeof(buffer), INI_FILE_PATH );//讀取 配置文件 需要引入 <windows.h>
 // cout<<buffer;
 char* iniValue=0; char* lable="Log"; char* anchor="Level"; //lable="Log";
 //anchor="Level";
 readIniValue(lable,anchor,iniValue); std::cout << iniValue << '\n';  return 0;
}


編譯時 提示如下錯誤信息:

demo1.cpp: In function 'int main()':

demo1.cpp:38:14: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

demo1.cpp:39:15: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

C:\Users\ADMINI~1\AppData\Local\Temp\cclOz7l9.o:demo1.cpp:(.text+0x3e): undefined reference to `readIniValue(char*, char*, char*)'

collect2.exe: error: ld returned 1 exit status

從錯誤信息中分析,應(yīng)該是頭文件沒有起作用??墒菂⒖枷嚓P(guān)一些相關(guān)頭文件的使用。未發(fā)現(xiàn)問題之所在。還請哪位大俠給予幫助


向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI