Author Archives: Robins

How to Solve error C2039: “to_ String “: not a member of” STD “

To_string is a function only available in C++11. This error is probably the reason why it was used in older versions of C++Solutions:

#include <string>
#include <sstream>

template <typename T>
std::string to_string(T value)
{
	std::ostringstream os ;
	os << value ;
	return os.str() ;
}

int main()
{
	std::string perfect = to_string(5) ;
}

“//./root/CIMV2” because of error 0x80041003. Events cannot be delivered through this filter until t…

windows system log error messages:

Event filter with query “SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA “Win32_Processor” AND TargetInstance. LoadPercentage > 99″ could not be reactivated in namespace “//. /root/CIMV2” because of error 0x80041003. Events cannot be delivered through this filter until the problem is corrected.

Solution:

On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
X = 0
T = True
While T
    Input = InputBox("Filename Lowercase Batch Convertor" & vbCrLf & vbCrLf & _
    "Please input the destination folder name. e.g. C:\Webmaster" & vbCrLf & vbCrLf & _
    "Note: Do NOT add '\' in the end of folder name!","FLowercase Convertor","C:\")
    If Input = "" Then
        MsgBox"Folder name is empty!",48,"Error!"
        T = True
    Else T = False
    End If
WEnd
MsgBox"All files names of " & Input & " will be converted to lowercase now...",64,"Note"
fold(Input)
MsgBox"Done! Total " & X & " file(s) were converted to lowercase.",64,"Done"
Sub fold(Path)
    Set f = fso.GetFolder(Path)
    Set rf = fso.GetFolder(Path).files
    Set fc = f.SubFolders
    For Each fff In rf
        lcf1 = LCase(fso.GetAbsolutePathName(fff))
        fso.MoveFile fff, lcf1
        X = X + 1
    Next
    For Each f1 In fc
        fold(f1)
        Set file = fso.GetFolder(f1).files
        For Each ff In file
            lcf = LCase(fso.GetAbsolutePathName(ff))
            fso.MoveFile ff,lcf
        Next
    Next
End Sub

Error while trying to run project:unable to start debugging.the debugger is not properly installed. run setup to install or repa

Error while trying to run project:unable to start debugging. the debugger is not properly installed. run setup to install or repair the debugger。

Solution 1: Run the Visual Studio .NET Add/Remove feature from “Control Panel > Add or Remove Programs”, by selecting the correct version of Visual Studio and clicking on “Change/Repair” button. In my case this solution did not fix the problem.

Solution 2: Reinstall .NET Framework debugging services.

Open command prompt
Type “cd /d %windir%/Microsoft.NET/Framework/”
regsvr32.exe mscordbi.dll
Unfortunately, this solution did not fix my problem either.

Solution 3: Manually register mdm.exe.

Open command prompt
Type “%CommonProgramFiles%/Microsoft Shared/VS7Debug/mdm. exe” /regserver
This solution did not work for me either.

Mysqldump: Got error: 1045: Access denied for user ‘root‘@‘localhost‘

(using password: NO) when trying to connect,mysqldump: [Warning] Using a password on the command line interface can be insecure,mysqldump Export error,linux export mysql database error mysqldump:got error:1045

mysqld Ver 5.7.24 for Linux on x86_64 (MySQL Community Server (GPL))

Edit mysql configuration file

vim /etc/my.cnf


Analysis of reasons:
Verify that the username and password are correct. The password contains special symbols (such as ~! @$%^& *()_ etc.) Remember to wrap the “password” in quotation marks, or consider changing the password to try to locate the problem.

Error lnk2038: detected “_ ITERATOR_ DEBUG_ Mismatched ‘level’ value of ‘0’

Problem description: the C++ program developed by Visual Studio 2010, after adding the h and CPP files of the third-party library, reported the following error when compiling and running:
Error LNK2038: “_ITERATOR_DEBUG_LEVEL” mismatches detected: value “0” mismatches value “2”Problem analysis: _ITERATOR_DEBUG_LEVEL is the system variable that records the compilation mode, 0 means that the current project is the Debug version, 2 means that the current project is the Release version.

Possible reasons 1:

Error 25 error LNK2038: Mismatch detected for "_ITERATOR_DEBUG_LEVEL": value "0" does not match value "2”

This problem is caused because the current project is the Debug version, but the library file referenced is the Release version.

“_ITERATOR_DEBUG_LEVEL” mismatch: value "2" does not match value "0"   

If the above problem is detected, then Release mode refers to Debug’s library file. This type of problem requires careful version matching when referring to files
Solution: Fix the lib file name in the attachment dependency. In Debug mode, you just use the file name of the Debug DLL, and in Release mode, you just use the Release DLL. (Debug mode DLL files usually have d, in, at the end of the file name)

Possible cause 2: Incorrect project property Settings, solution — “properties” — “C/C++–” Code generation — “runtime properties.
This property should be set to “multi-threaded debugging DLL (/MDd)” in Debug mode and” multi-threaded DLL (/MD) “in release mode. The above problem can also occur if the Settings are reversed.
Ending method: Just modify the runtime properties according to the schema.

Possible reason 3: If neither of the above reasons is true, the _ITERATOR_DEBUG_LEVEL variable may have been artificially assigned in the code.
For example, the basicexcel.cpp file contains the following statements:

#ifdef _DEBUG
#define _ITERATOR_DEBUG_LEVEL 0	// speedup iterator operations while debugging
#endif

The same problem may occur if _ITERATOR_DEBUG_LEVEL is set to 0 in Debug mode in order to speed up the program running in Debug mode, so that _ITERATOR_DEBUG_LEVEL values do not match in Debug mode.

Solution: Changing _ITERATOR_DEBUG_LEVEL to an appropriate value in the program can solve the problem.

How to Solve Error: “initializer element is not constant”

1. First, solve the problem of error reporting as shown in the title;

Take a look at the following code:

#include <stdio.h>  
int a = 1;  
int b = 2;  
int c = a+b;  
  
int main() {  
    printf("c is %d\n", c);  
    return 0;  
}  

Error during compilation of GCC-O test test.c: Initializer Element is not Constant

Reason: the value of the global variable C cannot be determined at compile time; it must be determined at run time. Why is that?Because this is the standard:
C language standard: Initializers of external variables and static variables must be constant expressions [1].
So the solution:

#include <stdio.h>  
int a = 1;  
int b = 2;  
int c; 
  
int main() {  
    c = a + b; 
    printf("c is %d\n", c);  
    return 0;  
}

———-
Similarly, the following code does not compile, and the error message is the same as above: [4]

char * p1 = (char *) malloc(10);  
int main(void)
{
。。。   
}

2. Do GCC and g++ compile according to the suffix name of the file?

If you change the source file name *.c to *.cc, and then compile with g++, no error will be reported. Even if you just change the file name to *.cc, the compiler will also compile with GCC, which can also compile the past. What is the reason?

————–
Principle:
GCC started out as GNU C Compiler, which is, as you know, a C Compiler. But later, as the project integrated more compilers in different languages, GCC stood for the GNU Compiler Collection, thus representing a Collection of compilers.
So instead of calling GCC when you compile your code, it’s more like a driver that calls the c compiler or the c++ compiler (g++) based on the suffix of your code. For example, if your code suffix is *.c, it will call the C compiler and linker to link to C’s library. If your code suffix is CPP, it will call the g++ compiler, and of course the library call will also use the c++ version (however, the GCC command does not automatically link to the library used by c++ programs, you must follow the parameter gcc-lstdc ++)

—————–
Here’s a piece of code:

#include <iostream>

using namespace std;

int a = 1;
int b = a;

int main()
{
cout << b << endl;

}

The Initializer Element is not constant because GCC identifies the code as C, and C specifies that initializing global variables must be a constant expression.
If $GCC test.cc, undefined reference to ‘STD ::cout’… Wait… Error: ld returned 1 exit status. Although GCC recognized c++ code at this time, it would not automatically link c++ code base, so ld link error appeared. At this point only need to manually specify and C ++ library link C: $GCC test.cc-LSTDC ++, at this point you can smoothly through the compilation link.

———————
G++ is the c++ compiler for GCC. At compile time, g++ calls GCC, so for c++ code, the two are equivalent. But since the GCC command does not automatically associate with the library used by c++ programs, it is common to use g++ for linking, so for the sake of uniformity, compile/link all use g++, giving the illusion that c++ programs can only use g++.
So you can understand it this way: you can compile with GCC /g++, and you can link with either g++ or gcc-lstdc ++. Because GCC commands do not automatically join with libraries used by C++ programs, g++ is usually used to complete the join. But at compile time, g++ automatically calls GCC, which is equivalent.
For the above code, just $g++ test.c will compile because g++ identifies *.c files as c++ files [2].

The compiler is through the program suffix name to determine the language is C or C ++. Specifically, if the suffix is.c, GCC treats it like a c program, and g++ treats it like a c++ program; CPP suffix, both are considered as c++ programs, note that although c++ is a superset of c, but the syntax requirements of the two are different [2], for c language and c++ language suffix name problem, see [7]
(3) for 1 is the C language standard, not C++, for C++, global variables and static variables do not have to follow the initialization must be constant expression such requirements, so, if the compiler to identify the above code into C++ code, then it can be successfully compiled in the past. (And the program USES the same libraries as the C language, so it’s ok not to add -LSTDC ++ parameter.

Therefore, since the suffix name of the file is changed to *.cc, I guess that whether GCC or g++, this file is identified as c++ file, so it is clear that since it is identified as c++ file, of course not to report an error.

3, compiler strong and weak symbols

In C, global variables default to 0 if they are not initialized, that is, in the global space:
int x =0; With the int x; The effect looks the same. The difference is very big, but here it is strongly recommended that you all global variables
to initialization, the main difference between them is as follows:

the compiler when compiling for both conditions can produce two kind of symbols in the symbol table of the target file, for initialization, called
symbol, an uninitialized, called weak symbols.

if the connector encounters two duplicate symbols while connecting to the target file, it will have the following processing rule:
if there are strong symbols with multiple duplicate names, it will report an error.
if there is a strong symbol and more than one weak symbol, the strong symbol shall prevail.
if there is no strong symbol, but there are more than one weak symbol with the same name, then choose any weak symbol.

————-
So here’s a piece of code:

#include<stdio.h>
int i;
i =1;
int main()
{
printf("%d\n", i);
}

GCC test. C
Can be compiled, but with warning: Data Definition has no type or Storage class
What does that mean?I =1, the definition of an I variable has no type;
So the code looks like this:

#include<stdio.h>
#include<stdlib.h>
 
int i;
j=1;
 
int main()
{
printf( "%d\n", j);
printf( "%d\n", i);
system( "pause" );
return 0;
}

gcc test.c
This code also has warning; data definition has no type or storage class
So for I =1; The compiler takes it as the definition + initialization of a variable.
and the int I before; Because I is equal to 1; So int I is weak, it doesn’t work; [3]

However, the above two pieces of code, if using g++ compiler, that is, according to the rules of c++ compiler, will be directly error:
“J does not name a type” because c++ is a mandatory language, can not be so casual!
It is worth noting that the first paragraph of the above two code also reports an error in g++ : “I does not name a type”. It is understandable that j compilation should not pass, because j is not defined at all. Int I = 1; int I = 1; Int j = 2; int c = a+b; G++ is passable. What’s the problem?See section 4 of this article.

————–
Here’s another piece of code:

#include <stdio.h>
struct stu
{
   long number;
};

struct stu  student; 
student.number = 1;  

int main(int argc, char * argv[])
{
 printf("%d\n", student.number);
}

Why is that?
The assignment statement should be placed in the function body!
Initialization can be outside the body of the function… But the assignment must be inside the body of the function…
Moreover, not only are structures assigned, but most statements (other than declarations and definitions of functions and variables) do not allow…
So understand the difference between initialization and assignment;
(This applies to C and C ++)
**** It should also be noted that in C language, struct is required when defining structural variables, while in C ++, it is not required. Stu Student = {1}; You can, but with struct you can compile it, you can run it.

4. Why is it specified that the initial values of global and static variables must be constant expressions?
Now that we’ve solved the problem, and we’ve analyzed why we did it, we can go deeper. Why do global variables and static variables have to be initialized as constant expressions?
Global (static) storage: Divided into DATA segments and BSS segments. The DATA section (global initialization section) holds initialized global and static variables; The BSS section (global uninitialized area) holds uninitialized global and static variables as well as initialized to zero global and static variables (see here). Automatic release at the end of the program. The BBS section is automatically cleared by the system before the program execution, so uninitialized global variables and static variables are already 0 before the program execution. – The program is released by the system after completion. [5]
——-
A comparison, for the statement:

int i = 3
int main()
{
    int j = i;
    ...
}

Instead of determining the value of the local variable J at compile time, the value of I is read at run time to assign to J. The compiled connected executable does not contain the value of J, only the code for the corresponding assignment statement. In contrast, since I is a global variable and is stored in static storage, its value needs to be determined at compile time. Space will be allocated in the target file to store the value of I. There will be no assignment statement to assign the value of I at run time, and there is no corresponding code.

for the statement:

int i = 3;
int j = i;

Because J is a global variable and is stored in static storage, its value also needs to be determined at compile time. I is a variable, not a constant, and the value of I cannot be determined at compile time, which means that the value of J cannot be determined at compile time, so C will report an error.
Instead, C++ simply puts j as an uninitialized global variable in the.bss area at compile time, with the default value of 0, and then adds a statement to assign j at run time, ensuring that this statement is executed before the main function begins. So the initialization of j is actually done at run time. [6]

So, we can now answer the question raised in red in section 3:
1. For int I = 1; int j = 2; int c = a+b; This sentence, in g + + through because the statement is the c at compile time as a variable declaration, because the front of the variable c has keyword int, then the compiler will be additional add a statement c = a + b, and ensure that the statement before the main function, g + + this way to make this statement to the right by compiling.
2. For int I; I = 1; G++ does not compile. The reason is that an assignment statement like I = 1, which is different from an int c = a+b, requires a value at run time; I =1 cannot be regarded as a declaration of a variable (I variable has no type in front of it),,,,,,, etc

Tip: GCC compiler plus the -v parameter, displays compile-time details, compiler version, compilation process, etc.

How to Solve Node start error listen eacces 0.0.0.0:810

Error Message:
events. js:141
throw er; // Unhandled ‘error’ event
^
Error: listen EACCES 0.0.0.0:80
at Object.exports. _errnoException (util.js:870:11)
at exports. _exceptionWithHostPort (util.js:893:20)
at Server. _listen2 (net.js:1224:19)
at listen (net.js:1273:10)
at net. js:1382:9
at nextTickCallbackWith3Args (node.js:452:9)
at process. _tickCallback (node.js:358:17)
at Function.Module.runMain (module.js:444:11)
at startup (node.js:136:18)
at node.js:966:3
———————————-

1. one is the port is occupied
2. sudo node xx. js — root privileges are required to access ports below 1024

 

Brief introduction of Linux MMAP and solution of bus error

Bus error occurs when mMAP Shared memory is used for communication between unrelated processes. 

Introduction to MMap communication mechanism
About the mmap

Mmap maps a file or other object into memory. A file is mapped to multiple pages, and if the file size is not the sum of all pages, the unused space of the last page is cleared. Munmap does the opposite, removing the object map for a specific address area.
When mmap is used to map the file to the process, the virtual address can be directly operated for file reading and writing operations, and there is no need to call read,write and other system calls. Note, however, that writing directly to this segment of memory does not write anything larger than the current file size.

An obvious benefit of using Shared memory communication is efficiency,
Because the process can read and write directly to memory without any copy of the data. For communications such as pipes and message queues, there are four copies of the data in the kernel and user space, and only two copies of the data in Shared memory: once from the input file to the Shared memory area, and once from the Shared memory area to the output file. In fact, when processes share memory, they do not always unmap after reading and writing a small amount of data, and re-establish the Shared memory area when there is new communication. Instead, the Shared area is kept until the communication is complete, so that the data content is kept in Shared memory and not written back to the file. Content in Shared memory is often written back to the file when the map is unmapped. Therefore, using the Shared memory communication method is very efficient.

Introduction to the MMAP function

Void * START, size_t length, int PROt,int FD, OFF_t offset);

Parameter description:

Start: The start address of the mapping area.
length: the length of the desired mapping area.
prot: the desired memory protection flag cannot conflict with the open mode of the file. Is one of the following values that can be reasonably combined by an OR operation.
 PROT_EXEC// pages can be executed
 PROT_READ/page/content can be read
 PROT_WRITE// page can be written to the
 PROT_NONE // page not accessible

flags: specifies the type of mapping object, mapping options, and whether the mapping page can be Shared. Its value can be a combination of one or more of the following bits. MAP_SHARED is generally used.
MAP_SHARED// Shared with all the process of mapping the object mapping space. Writes to a Shared area, equivalent to output to a file. The file is not actually updated until either Msync () or Munmap () is invoked.

fd: valid file description. If MAP_ANONYMOUS is set, the value should be -1 for compatibility issues.
offset: offset of the mapped object content (generally 0).

 

Bus Error solution

After mMAP, when the memory copy is made, the write() function is first used to write to the file descriptor that has been opened.

 

Reference code

Write:

<span style="font-size:12px;">// Arthur: zhangxiao
// Data: 2014/12/24	
// Note: mmap write
/*******************/

#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
//#define FILENAME "/home/zhangxiao/embededSystem/example/Mmap/test"

#define FILENAME "/tmp/test"
#define BUFLEN 128	
typedef struct
{
	char name[BUFLEN];
	int  id;
}people;

int main(int argc, char** argv) 
{
	int i;
	unsigned int pmap=0;
	int fd;
	fd=open(FILENAME ,O_CREAT|O_RDWR|O_TRUNC,00777 );
	assert(fd !=-1);
	pmap = (unsigned int)mmap(0,sizeof(people),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
	assert(pmap!=-1);
	write(fd," ",sizeof(people)); //write something
	unsigned int addr;
	addr=pmap;
	char tempname[30]="helloworld";
	int tempid=253; 
	addr = pmap + sizeof(char)*BUFLEN;	
	memcpy((void *)pmap,tempname,strlen(tempname)+1);
	memcpy((void *)addr, &tempid,sizeof(int));
	munmap((void *) pmap,sizeof(char)*BUFLEN);
	close(fd);
	printf("umap ok\r\n");
	return 0;
}</span><strong style="color: rgb(255, 0, 0); font-size: 19px;">
</strong>

Read:

// Arthur: zhangxiao
// Data: 2014/12/24	
// Note: mmap read 
/*******************/
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
//#define FILENAME "/home/zhangxiao/embededSystem/example/Mmap/test"
#define FILENAME "/tmp/test"
#define BUFLEN 128	
typedef struct
{
	char name[BUFLEN];
	int  id;
}people;

int main(int argc, char** argv) 
{
	int i;
	unsigned int pmap=0;
	int fd;
	fd=open(FILENAME ,O_CREAT|O_RDWR,00777 );
	assert(fd !=-1);
	pmap = (unsigned int)mmap(0,sizeof(people),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
	unsigned int addr;
	addr = pmap + sizeof(char)*BUFLEN;	
	printf("id=%d   name=%s\n\r",*((int *)addr),(char *)pmap);	
	munmap((void *) pmap,sizeof(char)*BUFLEN);
	close(fd);
	printf("umap ok\r\n");
	return 0;
}

 

Makefile:

CROSS = gcc

flags=-o
all:mmap_read mmap_write

mmap_read:mmap_read.c
	$(CROSS) $(flags) mmap_read mmap_read.c
mmap_write:mmap_write.c
	$(CROSS) $(flags) mmap_write mmap_write.c

clean:
	rm -rf mmap_read mmap_write<strong>
</strong>

 

Mysqli::stmt Fatal error: Call to a member function bind_param() on a non-object in …

$name = “Ming”;
$sex = “male”;
$age=20;
$sql=”insert into student(name,sex,age) values (?,?,?,?) “;
$mysqli_stmt=$mysqli-> prepare($sql);
$mysqli_stmt-> bind_param(‘ssi’, $name,$sex,$age);No syntax error is indicated, but data insertion is always unsuccessful. On checking, $SQL =”insert into Student (name,sex,age) values (?,?,?,?) “; One too many?, there is no corresponding parameter.

Error occurred during initialization of VM Could not reserve enough space for 1572864KB object heap

Error during initialization of VM Could not reserve enough space for 1572864KB object heap
The error occurred when the virtual machine initialization
could not have stored enough space for 1572864 KB Object heap

Java virtual machine (JVM) allocated more memory than the system had available, so there was not enough space allocated to the JVM to create objects
Solutions:
1. Modify gradle.properties file
to change -xmx1536m to -xmx512m, save, Rebuild

TIP:
-xmx is to set the memory size of the VM, if the program is very memory hungry, you need to set it with this parameter. 
-Xmx512m is the maximum amount of heap memory the JVM is allowed to allocate, on demand.
-cp is the classpath, the path to load classes

2, in the personal folder (C:/Users/username /. Gradle or ~ /. Gradle)) create gradle. The properties file, add

org.gradle.jvmargs=-Xmx512m -XX:MaxPermSize=512m