求助!C++ 实践之引入外部头文件失败
本来想整合一下,这两天学习的内容,发布一个具备读写ini、写日志的demo。谁想到新的问题出来,按照原思路。创建common.cpp 将一些工具方法归纳其中。demo1.cpp通过引入common.h文件 实现方法的调用。
关键代码如下:
common.cpp:
/***这是一个工具类的对象*/#include<windows.h>#include<string.h>#defineINI_FILE_PATH".//study.ini"#defineLOG_FILE_NAME"studylog"#defineLOG_VALUE_MAXSIZE80voidreadIniValue(char*lable,char*anchor,char*iniValue){charbuffer[LOG_VALUE_MAXSIZE];GetPrivateProfileString(lable,anchor,NULL,buffer,sizeof(buffer),INI_FILE_PATH);//读取配置文件需要引入<windows.h>iniValue=newchar[sizeof(buffer)+1];strcpy(iniValue,buffer);}
commom.h:
#ifndefCOMMON#defineCOMMON/***读取配置文件*@paramlabel日志文件 标签*@paramanchor日志文件锚点*@paraminiValue读取到日志的值*/voidreadIniValue(char*lable,char*anchor,char*iniValue);#endif
demo1.cpp:
/*这个案例用于说明C++读取配置文件写入日志文件2017-08-03*//***这个案例用于说明C++读取配置文件写入日志文件*@paramargc[description]*@paramargv[description]*@return[description]*@createTime2017-08-03*/#include"common.h"#include<iostream>#include<windows.h>//读取ini文件引入必要文件usingnamespacestd;//定义全局变量//#defineINI_FILE_PATH".//study.ini"//#defineLOG_FILE_NAME"studylog.txt"//voidreadIniValue(char*lable,char*anchor,char*iniValue){//charbuffer[80];//GetPrivateProfileString(lable,anchor,NULL,buffer,sizeof(buffer),INI_FILE_PATH);//读取配置文件需要引入<windows.h>//std::cout<<buffer<<'\n';//////iniValue=newchar[sizeof(buffer)+1];//strcpy(iniValue,buffer);////}intmain(){//整理读取配置ini配置文件//charbuffer[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';return0;}
编译时 提示如下错误信息:
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
从错误信息中分析,应该是头文件没有起作用。可是参考相关一些相关头文件的使用。未发现问题之所在。还请哪位大侠给予帮助
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。