我正在编写一些代码,它应该做的是将路径返回到没有文件名本身的文件。这里是
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
int main() {
char binaryPath[MAX_PATH]; //I think my problems stem from the fact that
//isnt truly a string
GetModuleFileName(NULL, binaryPath, MAX_PATH); //Get filename
string i = (string) binaryPath;
string fileDir = "";
int tempSlashes = 0;
for (int x = 0; x < strlen(binaryPath); x++) {
if (i[x] == '\\') { //In eclipse CDT this gives warning 1 (below)
tempSlashes++;
}
}
for (int y = 0; y < tempSlashes; y++) {
fileDir.append(binaryPath[y]); //Line gives warning 2
}
cout << fileDir;
return 0;
}
无论如何,小警告注释
Error 1:
Multiple markers at this line
- comparison with string literal results in unspecified behaviour [-
Waddress]
- ISO C++ forbids comparison between pointer and integer [-
fpermissive]
Error 2:
Multiple markers at this line
- Invalid arguments ' Candidates are: std::basic_string<char,std::char_traits<char>,std::allocator<char>> & append(const
std::basic_string<char,std::char_traits<char>,std::allocator<char>> &) std::basic_string<char,std::char_traits<char>,std::allocator<char>> & append(const
std::basic_string<char,std::char_traits<char>,std::allocator<char>> &, unsigned int, unsigned int) std::basic_string<char,std::char_traits<char>,std::allocator<char>> & append(const
char *, unsigned int) std::basic_string<char,std::char_traits<char>,std::allocator<char>> & append(const char *) std::basic_string<char,std::char_traits<char>,std::allocator<char>> &
append(unsigned int, char) std::basic_string<char,std::char_traits<char>,std::allocator<char>> & append(#10000, #10000) '
- invalid conversion from 'char' to 'const char*' [-fpermissive]
程序本身拒绝编译,并运行较早的 .exe
我不确定我在这里做错了什么,帮助(以及解释)会非常好。
谢谢!