I'm trying to build a program for release, but even though it works fine in a debug configuration, I am getting this error when I use the release configuration:
1>c:\users\owner.ben-pc\documents\visual studio 2010\projects\xsp quick unpacker\xsp quick unpacker\Form1.h(217): error C2664: 'DeleteFile' : cannot convert parameter 1 from 'const char *' to 'LPCTSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
I tried adding the "#define _SECURE_SCL 0" line as per this thread, but that didn't change anything.
Here's the part of the program that the line that is throwing the error is in (the "DeleteFile(temp);" is the specific line that throws the error):
path=this->FilePathBox->Text;
if (!File::Exists(path+"\\filemaker\\start.ini"))
{
FileStream^ fs=File::Create(path+"\\filemaker\\start.ini");
delete fs;
}
else
{
marshal_context^ context=gcnew marshal_context();
String^ filepath=path+"\\filemaker\\start.ini";
const char* temp;
temp=context->marshal_as<const char*>(filepath);
DeleteFile(temp);
delete context;
}
P.S. I'm using VS 2010 Premium.
Related
Visual Studio gives me this error when I try to compile my C++ project:
Severity: Error
Code: C2678
Description: binary '=': no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion)
Project: jr
File: c:\program files (x86)\microsoft visual studio 14.0\vc\include\utility
Line: 192
I suppose, somewhere in my project, I'm trying to change constant string.
How do I locate this? How to go about debugging such errors?
The filename and line mentioned in the error are some read-only files by Microsoft. I'd like to locate the error in my code. Here's the excerpt of code around line 192:
_Myt& operator=(const _Myt& _Right)
{ // assign from copied pair
first = _Right.first;
second = _Right.second;
return (*this);
}
You probably want to write code like:
const std::string s;
s = "";
this is why error is saying about const type : 'const std::string'
Other possibility is that you want to assign a value to a string in a const method.
Note: pls don't be confused with other Stackoverflow questions that have the same title/errocode -- they are mostly due to missing #include <string> but it's not the issue here.
I'm reading Pretty-print C++ STL containers question and downloaed Kerrek's code from his GitHub Project cxx-prettyprint, when I try compile it (my environment is Windows 7, Visual Studio 2013, compiled project as a Console Application "Use Multi-Byte Character Set"), hit a template deduction error.
It's a bit weird as suggested by Mike Kinghan in the comment, it does compile compiles and runs fine with the current MSVC++ : see it online.
I'm confused, there must be something wrong with my configuration. I created a blank new Windows Console Application, and added Kerrek's code in, focus on a vector of string test cast, removed other scenarios such as set/map etc:
int main(int argc, char* argv[])
{
std::vector<std::string> v;
v.push_back("hello, world");
v.push_back("2nd line");
v.push_back("last line");
std::cout << v;
}
, now hit a error:
Error 1 error C2679: binary '<<' : no operator found which takes a
right-hand operand of type
'std::vector>' (or there is no
acceptable conversion)
If I explicitly call the pretty_print::operator <<,
pretty_print::operator<<(std::cout, v);
, hit another template deduction error:
Error 1 error C2784: 'std::basic_ostream<_Elem,_Traits>
&pretty_print::operator <<(std::basic_ostream<_Elem,_Traits> &,const
pretty_print::print_container_helper
&)' : could not deduce template argument for 'const
pretty_print::print_container_helper
&' from 'std::vector>'
It only compiles if the print_container_helper is explictily created:
pretty_print::print_container_helper<std::vector<std::string>, char, ::std::char_traits<char>, pretty_print::delimiters<std::vector<std::string>, char>>
vh(v);
pretty_print::operator<<(std::cout, vh);
The full code is here: http://rextester.com/RJX76690
I am building a .SM2 and .RM2 extractor/compiler for a game but I am having trouble with the code. I am not experienced in C++ at all and the code is source code given by the original creator. Even his original file that wasnt edited by me had errors but he still made the program. Can someone please help me with the errors?
Errors:
Error1: error C2664: 'CreateDirectoryW' : cannot convert parameter 1 from 'const char [25]' to 'LPCWSTR'
Error2: error C2664: 'CreateDirectoryW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'(X3)
Error4: error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'char [256]' to'LPCWSTR'
Error5: error C2440: 'initializing' : cannot convert from 'WCHAR [260]' to 'char*'
Here is my code that apparently have the errors:
CreateDirectory(".\\TESTFOLDER\\TESTFOLD2ER", NULL); (This is for Error 1)
CreateDirectory(string, NULL);
break; (This is for Error2)
if ((hdl = FindFirstFile(asteriskpath, &data)) == INVALID_HANDLE_VALUE)
return; (For Error3)
char* filename = data.cFileName;
char current_dir[256]; (For Error4)
Please help,
Thanks,
Cameron
Sawaya
Method 1: set your project character setting to Use Multi-Byte Character Set:
Configure Properties > General > Project Defaults > Character Set > Use Multi-Byte Character Set
Method 2:
For Error 1/2/4:
You should convert char[] to wchar_t[] first before passing to CreateDirectory() (For your Error 1, similar for other errors 2 and 4) as they are using different character encoding types. Try swprintf with the %hs flag.
Example:
wchar_t ws[100];
swprintf(ws, 100, L"%hs", ".\TESTFOLDER\TESTFOLD2ER");
For Error 5:
You can use the wcstombs function to convert wchar_t[] to char[], reference here.
I'm using Microsoft Visual C++ 6.0 and Microsoft Visual Studio 2008 to develop an academic computer vision project.
In this project i need to use OpenCV 1.1 (http://opencv.willowgarage.com/) and CvBlob (http://code.google.com/p/cvblob/).
I tried to compile this project with Microsoft Visual Studio 2008 and it compiles without errors.
With Visual C++ 6.0 i got a lot of errors.
OpenCV are not responsible of this behavior, because a trivial project with only OpenCV (without CvBlob) works well.
To understand the errors better I made an empty project with only the CvBlob inclusion.
I paste here a brief summary of the errors:
cvcontour.cpp(253) : error C2371: 'i' : redefinition; different basic types (and others similar to this. i solved with variable redefinition, every time)
cvcontour.cpp(318) : error C2664: 'thiscall std::vector<struct CvPoint,class std::allocator<struct CvPoint> >::std::vector<struct CvPoint,class std::allocator<struct CvPoint> >(unsigned int,const struct CvPoint &,const class std::allocator<struct CvPoint> &)' : cannot convert parameter 1 from 'class std::deque<struct CvPoint,class std::allocator<struct CvPoint> >::iterator' to 'unsigned int' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
cvtrack.cpp(278) : error C2440: 'initializing' : cannot convert from 'struct cvb::CvTrack *const ' to 'struct cvb::CvBlob *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Have you ideas on how can i solve these problems?
Thanks in advance for the help!
-------- UPDATE --------
I tried to edit and correct the code in order to elminate the three errors in my question.
The error C2664 seems to be the more difficult to cirmumvent...
I have replaced the indicted line
return new CvContourPolygon(dq.begin(), dq.end());
where CvContourPolygon is a typedef std::vector<CvPoint> CvContourPolygon;
with
deque<int>::iterator dq_it;dq_it = dq.begin();
CvContourPolygon v_tmp;
v_tmp.push_back(*dq_it);
while (dq_it != dq.end()){
v_tmp.push_back(*dq_it++);
}
First, what that i wrote is correct? Than, how can i solve the errors that occured from this?
Thank you in advance!
Errors (suppose that the first line is 318:
cvcontour.cpp(319) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::deque<struct CvPoint,class std::allocator<struct CvPoint> >::iterator' (or
there is no acceptable conversion)
cvcontour.cpp(321) : error C2664: 'push_back' : cannot convert parameter 1 from 'int' to 'const struct CvPoint &'
Reason: cannot convert from 'int' to 'const struct CvPoint'
No constructor could take the source type, or constructor overload resolution was ambiguous
cvcontour.cpp(322) : error C2679: binary '!=' : no operator defined which takes a right-hand operand of type 'class std::deque<struct CvPoint,class std::allocator<struct CvPoint> >::iterator' (or there is no acceptable conversion)
cvcontour.cpp(322) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
-------- UPDATE2 --------
This code seems to work correctly!
deque<CvPoint>::iterator dq_it;
dq_it = dq.begin();
CvContourPolygon v_tmp;
for (dq_it = dq.begin(); dq_it != dq.end(); ++dq_it){
v_tmp.push_back(*dq_it);
}
//return new CvContourPolygon(dq.begin(), dq.end());
return &v_tmp;
C2371 - VC6 was sloppy with scope of local variables. Should be able to fix this by making the code use variable names unambiguously.
C2664 - looks like failure to initialize a vector using deque iterators - wrong overload on vector::vector() being called? Probably have to work around this by manually copying the deque elements to the new vector somehow.
C2440 - check the objects are compatible (VS2008 seems to think so) and add the appropriate cast.
EDIT:
Shouldn't your code look like this?
deque<CVPoint>::iterator dq_it;dq_it = dq.begin();
CvContourPolygon v_tmp;
for (dq_it = dq.begin(); dq_it != dq.end(); ++dq_it)
{
v_tmp.push_back(*dq_it);
}
I've been trying to get back into coding for a while, so I figured I'd start with some simple SDL, now, without the file i/o, this compiles fine, but when I throw in the stdio code, it starts throwing errors. This I'm not sure about, I don't see any problem with the code itself, however, like I said, I might as well be a newbie, and figured I'd come here to get someone with a little more experience with this type of thing to look at it.
I guess my question boils down to: "Why doesn't this compile under Microsoft's Visual C++ 2008 Express?"
I've attached the error log at the bottom of the code snippet. Thanks in advance for any help.
#include "SDL/SDL.h"
#include "stdio.h"
int main(int argc, char *argv[])
{
FILE *stderr;
FILE *stdout;
stderr = fopen("stderr", "wb");
stdout = fopen("stdout", "wb");
SDL_Init(SDL_INIT_EVERYTHING);
fprintf(stdout, "SDL INITIALIZED SUCCESSFULLY\n");
SDL_Quit();
fprintf(stderr, "SDL QUIT.\n");
fclose(stderr);
fclose(stdout);
return 0;
}
Actual errors reported:
main.cpp(6) : error C2090: function returns array
main.cpp(6) : error C2528: '__iob_func' : pointer to reference is illegal
main.cpp(6) : error C2556: 'FILE ***__iob_func(void)' : overloaded function differs only by return type from 'FILE *__iob_func(void)'
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(132) : see declaration of '__iob_func'
main.cpp(7) : error C2090: function returns array
main.cpp(7) : error C2528: '__iob_func' : pointer to reference is illegal
main.cpp(9) : error C2440: '=' : cannot convert from 'FILE *' to 'FILE ***'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(10) : error C2440: '=' : cannot convert from 'FILE *' to 'FILE ***'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(13) : error C2664: 'fprintf' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(15) : error C2664: 'fprintf' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(17) : error C2664: 'fclose' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(18) : error C2664: 'fclose' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
#include "SDL/SDL.h"
#include "stdio.h"
int main(int argc, char *argv[])
{
FILE *stderr; //Invalid names. These are already defined by stdio.h.
FILE *stdout; //You can't use them (portably anyway).
stderr = fopen("stderr", "wb"); //I'm assuming you actually want files
stdout = fopen("stdout", "wb"); //called "stderror" and "stdout".
SDL_Init(SDL_INIT_EVERYTHING);
fprintf(stdout, "SDL INITIALIZED SUCCESSFULLY\n");
SDL_Quit();
fprintf(stderr, "SDL QUIT.\n");
fclose(stderr);
fclose(stdout);
return 0;
}
Try changing the names stderr and stdout to something else. I suspect the compiler is complaining because these are already defined elsewhere in the C library.
You don't need to declare, open, or close stdin, stdout or stderr, that's already done for you in stdio.
If you're using C++, why not iostream?