在VS2008的Debug32模式和Dos下运行程序时对于“./”的理解

  本文要比较的是在VS2008Debug32模式和Dos下运行程序时对于“./”的理解。

如下所示,是一个简单的C/C++程序:

  1. #include <stdio.h>
  2. #include <tchar.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <windows.h>
  6. int _tmain(int argc, _TCHAR* argv[])
  7. {
  8.     FILE* fpr;
  9.     char msgFile[80];
  10.     char dir[80];
  11.     char file[80];
  12.     char buf[80];
  13.     memset(msgFile, '/0', 80);
  14.     memset(dir, '/0', 80);
  15.     memset(file, '/0', 80);
  16.     memset(buf, '/0', 80);
  17.     GetPrivateProfileString("TEST""MSG_DIR""F://vs2008//Test", (LPTSTR)dir, 80, "F://vs2008//Test//Test.ini");
  18.     GetPrivateProfileString("TEST""MSG_FILE""message.dat", (LPTSTR)file, 80, "F://vs2008//Test//Test.ini");
  19.     strcpy_s(msgFile, 80, dir);
  20.     strcat_s(msgFile, 80, "//");
  21.     strcat_s(msgFile, 80, file);
  22.     if(!fopen_s(&fpr, msgFile, "r")){
  23.         fgets(buf, 80, fpr);
  24.         printf_s("%s/n", buf);
  25.     }
  26.     return 0;
  27. }

其中的Test.ini文件如下:

[TEST]

MSG_DIR=F:/vs2008/Test

MSG_FILE=message.dat

message.dat文件如下:

This is a test program!

上面的程序运行的结果如图1所示:

 

 

先对程序和Test.ini文件做如下修改:

程序:

GetPrivateProfileString("TEST", "MSG_DIR", ".", (LPTSTR)dir, 80, "F://vs2008//Test//Test.ini");

ini文件:

;MSG_DIR=F:/vs2008/Test

(前面加了一个分号,即注释这一行)

做上述改动后,在程序中msgFile的值就变成了“./message.dat”,此时运行程序得到的结果如图2所示:

 

 

也就是说,这时程序已经找不到message.dat文件了,那如何才能让程序找到message.dat文件呢?

你可以将message.dat文件放在F:/vs2008/Test/Test目录下,即将它和Test.cpp放在一起。

此时你如果再运行改过之后的程序运行结果就如图1所示了。

 

这时,我们不妨再做一个尝试,就是在dos命令行格式中运行Test.exe,如图3所示:

 

 

从图中可以看出,没有输出,也就是说,message.dat文件又找不到了。

这时,如果你将message.dat文件放在F:/vs2008/Test/Debug文件夹下,则它又能访问了,如图4所示:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
将QT += core QT -= gui CONFIG += c++11 TARGET = UavRectifyLoadLIb CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS win32{ CONFIG(debug, debug|release){ DESTDIR = $$PWD/../../../../RasterManager/bin/Debug } else{ DESTDIR = $$PWD/../../../../RasterManager/bin/release } INCLUDEPATH += $$PWD/../../../include/gdal1101 DEPENDPATH += $$PWD/../../../include/gdal1101 } else{ CONFIG(debug, debug|release){ DESTDIR = $$PWD/../../../product/release32 } else{ DESTDIR = $$PWD/../../../product/release32 } } # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 unix:!macx: LIBS += -L$$PWD/../../../product/release32/ -lUAVAutoRectifyMt -lUAVAutoRectify -lUAVAutoRectifyFi INCLUDEPATH += $$PWD/../include DEPENDPATH += $$PWD/../include unix:!macx: LIBS += -L$$PWD/../../../lib/opencvf249/ -lopencv_core unix:!macx: LIBS += -L$$PWD/../../../lib/opencvf249/ -lopencv_highgui unix:!macx: LIBS += -L$$PWD/../../../lib/opencvf249/ -lopencv_imgproc INCLUDEPATH += $$PWD/../../../lib/opencvf249 DEPENDPATH += $$PWD/../../../lib/opencvf249 unix:!macx: LIBS += -L$$PWD/../../../../../../../usr/local/lib/ -lopencv_core #unix:!macx: LIBS += -L$$PWD/../../../../../../../usr/local/lib/ -lopencv_highgui unix:!macx: LIBS += -L$$PWD/../../../../../../../usr/local/lib/ -lopencv_imgproc unix:!macx: LIBS += -L$$PWD/../../../../../../../usr/local/lib/ -lopencv_features2d unix:!macx: LIBS += -L$$PWD/../../../../../../../usr/local/lib/ -lopencv_imgcodecs INCLUDEPATH += $$PWD/../../../../../../../usr/local/include DEPENDPATH += $$PWD/../../../../../../../usr/local/include unix:!macx: LIBS += -L$$PWD/../../../product/release32/ -lDEMDriver unix:!macx: LIBS += -L$$PWD/../../../product/release32/ -lProjection unix:!macx: LIBS += -L$$PWD/../../../product/release32/ -lIImage_gC QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO 转为cmake格式
06-11

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值