我有两个 c++ win32 控制台应用程序项目。两者都有完全相同的代码。
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
if (argc != 3){
cout << "Program needs 2 arguments";
}
else{
string filePath = argv[1];
string flag = argv[2];
unsigned long int size;
bool najden = false;
//odpri datoteko
ifstream idatoteka(filePath, ios::in | ios::binary | ios::ate);
if (idatoteka){
if (flag != "-c" && flag != "-e"){
cout << "unknown flag";
}
else{
if (flag == "-c"){
//kompresija
}
else{
//dekompresija
}
}
}
else{
cout << "This file doesn't exist\n";
}
}
system("pause");
return 0;
}
愚蠢的是,其中一个给了我一个错误,我尝试将 argv[1] 和 argv[2] 传递给字符串变量。错误信息如下:
cannot convert from '_TCHAR *' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
从什么时候起这不起作用,两个相同的项目之一怎么可能产生错误?