w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Templatized ostream overload ambiguity error : basic_ostream vs const char[]
The non-template operator does not cause any ambiguity because that operator itself is not viable for resolving this call: return out << "a1"; // ^^^^^^^^^^^ // This MUST be `std::operator <<`, no other valid overload of // operator << is found! As well as the other similar ones. The template version, on the other hand, is viable, since T is not bound to be any concrete type: template <class T> ostream& operator<<(ostream& out, const T& a) { switch(a) { case T::a1 : return out << "a1"; // ^^^^^^^^^^^ // Here the compiler could invoke std::operator << // OR it could invoke your operator << template, // which is also viable since T could be anything! //

Categories : C++

C++ copying integer to char[] or unsigned char[] error
When you say i & 0xFF etc, you're creaing values in the range [0, 256). But (your) char has a range of [-128, +128), and so you cannot actually store those values sensibly (i.e. the behaviour is implementation defined and tedious to reason about). Use unsigned char for unsigned values. The clue is in the name.

Categories : C++

Unexpected Error C2632: 'char' followed by 'char' is illegal
Those types have already been created via typedef (maybe) or #define (more likely) before your code tries to do it; taking a look at the preprocessor output (if that's possible with Visual-C++) may help you track down why that is.

Categories : Visual C++

Java Error, required: char[] found char
The posted sample works if your target variable is of type char, so I assume that you are doing something wrong in the assignment. Maybe you are calling a function which requires a char[] in wich case you should use funct(letterGrade) without the [0]. If your problem persists you should post a bit more code. Update I fixed your code to make it compile. of course I don't know what it is supposed to be so I had to make some assumptions, but you should see how the syntax is supposed to be. public static void method() { double totalEarnedPoints = 1; double totalPossiblePoints = 1; double gradeScale[] = {1, 2, 3}; double gradeCutoffs[] = {1, 2, 3}; double gradePer = 0.0; char letter; double calcPercent = 1; gradePer = (totalEarnedPoints / totalPossiblePoints

Categories : Java

g++ gives error : invalid initialization of reference of type ‘char&’ from expression of type ‘unsigned char’
Why isn't it possible to initialize 'char &' with a variable of type 'unsigned char' while it is possible to initialize 'const char &' with it? Because the latter creates a temporary to bind to the const reference when the unsigned char is converted to a char, something you can't do with non-const references. char, signed char, and unsigned char are three distinct types, as explained in C++11 § 3.9.1: Plain char, signed char, and unsigned char are three distinct types

Categories : C++

is char** x = (char**) arg equivalent to reinterpret_cast(const_cast(arg) )?
Yes they are basically the same except the c++ style cast shows the reader of the code that you are doing some weird stuff while its harder to notice with the c style. Its legal yet as always its highly suspect when a const incoming parameter is being cast as non const.

Categories : C++

meta char set UTF 8 encoding error
You are not using UTF-8. You have just included some markup which tells the browser you are using UTF-8. That error message sounds like it is coming from your editor. You need to configure your editor to save in UTF-8.

Categories : HTML

Getting error: sed: -e expression #1, char 2: unknown command: `.'
This is the cause of the problem: for i in 1..$(seq 1 $(cat "somefile" | wc -l)) Try just for i in $(seq 1 $(wc -l < somefile)) However, you are reading your file many, many times too often with all those sed commands. Read it just once: read x1 y1 < <(sed 1q somefile) while read x2 y2 f3 f4; do if [[ $x1 = $x2 && $y1 = $y2 ]]; then x1=$x2 y1=$x2 fi echo "$f3 $f4" done < somefile > "$x1-$y1.txt" The line where you construct the s variable is truncated -- I'm assuming you have 4 fields per line. Note: a problem with cut-and-paste coding is that you introduce errors: you assign y2 the same field as x2

Categories : Bash

It would be better to be explicit if an 8k-char buffer is required. [ERROR]
Change this line from: BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8")); to this: BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"), 8192); It should remove that message

Categories : Android

C char pointers strcpy memory error
In the first case, you are declaring strA as a char *, pointing to static memory containing the string "Hello ". In the second case, you are creating an array of 6 characters, initialised with the string "Hello ". strcat in the first case thus tries to write to this static segment of memory, causing an error immediately. The second code, which is still invalid (as strA is not a large enough array to store "Hello World"), may or may not segfault as you aren't attempting to append to a string literal.

Categories : C

reference to a const char*, error C2664:
SerializeCStringHelper helper(lib.getName().c_str()); This line attempts to pass a temporary to the constructor of SerializeCStringHelper the problem is you cannot bind a temporary to a non-const reference. That is why SerializeCStringHelper helper(str); works, because str is not a temporary object. Example: #include <string> void foo(const char*& str) {} void bar(const char* const & str) {} int main() { std::string s("..."); //foo(s.c_str()); bar(s.c_str()); return 0; } This code will compile fine, because bar takes a const reference, but if you uncomment the call to foo, it will fail to compile because foo takes a non-const reference.

Categories : C++

IE8 jQuery error line:2 char:36689
Did you edit the layout code for this question?.. if so there are more than a handful of errors in your html. If not, validate and your problem may resolve. The following were changed from your original markup. Extra spaces in form enctype. type="text" declared in multiple select tags. multiple closing select tags that have no opening tag were removed. lone table cell tag removed. <form id="rentForm" method="post" action="rentsubmit.php" enctype="multipart/formdata"> <select id="rentmake" name="make" class="selectFields"> <option value="0">Select</option> <option value="Audi">Audi</option> <option value="BMW">BMW</option> </select> <select id="rentmodel" name="model" class="selectFields"> <option value="0">Select

Categories : Jquery

recv() C error invalid conversion from char to int
There are several issues with this code: char update[MAX_UPDATE_LEN]; int remoteLen; char pholder; pholder = recv(update,connectDescriptor,MAX_UPDATE_LEN,MSG_DONTWAIT); <-- error here remoteLen = atoi("pholder"); recv returns an ssize_t which is usually much bigger than a char. So you can't safely store the return code in pholder. The arguments to recv() are in the wrong order. Here's the declaration: ssize_t recv(int sockfd, void *buf, size_t len, int flags); atoi is being passed a string which is not a number "pholder". It expects a string like "12345". If ASCII-encoded numerals is what you expect, you can give update to atoi. Bonus: use sizeof(update) instead of MAX_UPDATE_LEN for len -- that way if the type declaration or size of update changes, you should still get the e

Categories : C

error: cannot convert ‘char*’ to ‘int*’ in assignment (also for 'double*' to 'int*')
error: cannot convert ‘char*’ to ‘int*’ in assignment This error is complaining about this line: ptr = new T [size]; Where earlier, ptr is declared as: int * ptr; The ptr = new T assignment won't work unless T is int when you're constructing your Template. To fix this, change the definition of ptr to: T * ptr;

Categories : C++

Syntax error at const char *sql_stmt
Please replace your code with this line const char *sql_stmt = [@"create table if not exists studentsDetail (regno integer primary key, name text, department text, year text)" UTF8String];

Categories : IOS

Unable to pass an address of array of type char *[2] to function taking char ***
char *array[2] = {"string", "value"}; is an array with 2 elements of char *. Using array as an address results to a pointer to the first element, i. e. of type char **. Using &array results to a pointer to the same place, but of type char *(*)[2] (not sure if the spelling is right). This is not the same as a char *** - the representation in memory is completely different. To be more verbose, +++++++++++++++++++++++ + array[0] + array[1] + +++++++++++++++++++++++ this is the array. char ** p1 = array; // is a pointer to the first element, which in turn is a pointer. char *(*p2)[2] = &array; // is a pointer to the whole array. Same address, but different type, i. e. sizeof(*p1) != sizeof(*p2) and other differences. char ***p3 = &p1; // Now, p1 is a different pointer va

Categories : C

char pointers, char arrays, and strings in the context of a function call
The char[] signature in the parameter is exactly the same as char*. In C++, it is illegal to convert a string constant char const* (the string "Kacy") to a char* because strings are immutable. Your second example compiles because the name is an actual array. There is no change to char*. As a solution, change your parameter to take a const string array: Student(char const name[]); which again is the same as String(char const *name); though you're better off using std::string: #include <string> class String { public: String(std::string name); };

Categories : C++

How to disable type char in JTextArea but enable removed char (Backspace)
try to put DocumentFilter instead of DocumentListener something like final AbstractDocument abstractDocument = (AbstractDocument) textArea.getDocument(); abstractDocument.setDocumentFilter(new DocumentFilter() { @Override public void remove(final FilterBypass fb, final int offset, final int length) throws BadLocationException { super.remove(fb, offset, length); } @Override public void insertString(final FilterBypass fb, final int offset, final String string, final AttributeSet attr) throws BadLocationException { if (getLineCountAsSeen(textArea) < 4) { super.insertString(fb, offset, string, attr); }

Categories : Java

C - Sort char string in array to equal char user input
OK, so basically you want to convert a sorted array of letters to a specific (random?) ordering and record the swaps along the way, right? Here is one way to do this. #define SWAP(a,b) a^=b;b^=a;a^=b int main(int argc, char* argv[]) { char* wordInput=argv[1]; char* newWord = (char*)malloc((strlen(wordInput) + 1) * (sizeof(char))); int i,j,k; fprintf(stdout, "Word is %s ", wordInput); // Sort wordInput into newWord. for (i=0; i<strlen(wordInput); i++) { // Put this one at the end. newWord[i]=wordInput[i]; // Start at the back of the string, and move it forward if it is less. for (j=i-1; j>=0; j--) { if (newWord[j+1] < newWord[j]) { SWAP(newWord[j+1], newWord[j]); } else { break; } } } newWord[strlen(wordInput)]

Categories : C

How can I write a function boolean succeeds(char a, char b, String s)? using s.equals(""), s.charAt(0), s.substring(1)
Something like this should work. I have not compiled this. Hopefully it gets you in the right direction, even with possible syntax errors. public boolean succeeds(char a, char b, String s){ boolean sawFirst= false; for(int i=0;i<s.length();i++){ if(!sawA){ if(s.charAt(i)==b) sawFirst = true; } else{ if(s.charAt(i)!=a) return false; else sawFirst= false; } } return true; }

Categories : Java

Function not returning char correctly: error during compile
you did not declare the function computerPlay() check after declaring this function. char computerPlay(void); add this statement after #include<stdio.h> EDIT: All identifiers in C need to be declared before they are used. This is true for functions as well as variables. For functions the declaration needs to be before the first call of the function. A full declaration includes the return type and the number and type of the arguments simple example : int sum (int, int); // declared a function with the name sum result =sum(10,20); // function call int sum (int a, int b) // defined a function called sum { return a + b; }

Categories : C

bash error sed: -e expression #1, char 3: unknown command: `/'
Error is here: sed -i "21/9.0E7/$n" Since you haven't provided any sed command after 21. Did you forget s (substitute switch) in your sed command? It should probably be: sed -i "s/9.0E7/$n/" OR may be this: sed -i "21s/9.0E7/$n/"

Categories : Bash

Passing function char argument returns error
Your functions argument types is a char *. So you don't need to use &cmd. Just using cmd will pass the base address of that array. So either you call the function like: getLine(cmd, &line); or change the function declaration like: int getLine(char **cmdl, char *str)

Categories : C

What does this error mean - "Instance of Num Char required for definition of versioncheck"?
One approach to solving this kind of problem—and one that I can recommend—is to feed your function definition to the compiler without the accompanying type signature and then use the interactive environment to inspect the type that the compiler inferred for the function. In your case, if we define versioncheck [] [] = True versioncheck (x:xs) [] |x /= 0 = False |otherwise = versioncheck xs [] versioncheck (x:xs) (y:ys) | x /= y = False | otherwise = versioncheck xs ys and then, in GHCi, query > :type versioncheck it gives us versioncheck :: (Eq a, Num a) => [a] -> [a] -> Bool making explicit that your function operates on two lists with elements drawn from the same type a and that this

Categories : Haskell

How compare a char / single char string - with some list of alphabets set
If the starting letter is always an English character (or anything representable by a reasonably small integer that fits into an unsigned char), then here's a solution (the fastest possible one I can think of - uses no jumps except for the first check for initialization and only plain old integers are used instead of the somewhat heavier-weight comparison of NSString instances): - (UIColor *)colorFromName:(NSString *)name { static UIColor *strs[1 << CHAR_BIT] = { nil }; static BOOL initted = NO; if (!initted) { strs['a'] = [UIColor greyColor]; strs['b'] = [UIColor whiteColor]; // ... strs['z'] = [UIColor blueColor]; initted = YES; } unsigned char first = tolower([name characterAtIndex:0]); return strs[first]; }

Categories : IOS

Why does GCC accept convertion from 'const char *' to 'char *' on std::strrchr() returned value?
Actually your g++ does not accept the conversion from 'const char *' to 'char *', it's just that on your version std::strrchr() returns a char* (incorrectly, instead of a const char*). To verify the first part of my statement, try to compile the following on your GCC versions, I predict that all will correctly issue an error: int main() { const char* p = "foo"; char* q = p; // error, invalid conversion from 'const char*' to 'char*' } Now for the second part, I tried to compile the following minimal code, whose actual aim is to trigger an error in order to list the declared overloads of std::strrchr: #include <cstring> void (*p)() = &std::strrchr; // error here, with "candidates are: ..." int main() {} Well, with gcc 4.7.2 the message shows the expected "all non-c

Categories : C++

Regarding type safety when storing an unsigned char value in char variable
"does this mean that char could maintain its 'signedness' throughout the comparison?" yes; -1 as a signed char will be promoted to a signed int, which will retain its -1 value. As for the unsigned char, it will also keep its 255 value when being promoted, so yes, the comparison will be false. If you want it to evaluate to true, you will need an explicit cast.

Categories : C

Printing the memory representation of an integer using char* and unsigned char*
This is because (on your system) char is signed, and it's getting promoted to int in the printf() call. Use unsigned char: void print_bytes(const unsigned char *ptr, size_t len) { for(size_t i = 0; i < len; ++i) { printf("%p %x ", ptr + i, ptr[i]); } }

Categories : C

What to call method which returns char* ( String in Java and char* in C++)?
It returns a String object and you can use the JNI string functions to convert that string to a char*: char* gPGGetName() { jobject objStr = env->CallObjectMethod(g_Obj, g_s3eGPGGetName); jsize len = env->GetStringUTFLength(objStr); const char* strPtr = env->GetStringUTFChars(objStr, 0); char* buffer = (char*)malloc((len + 1) * sizeof(char)); memcpy(buffer, strPtr, len); buffer[len] = ''; env->ReleaseStringUTFChars(objStr, strPtr); return buffer; }

Categories : Android

SaveToLayerFile_management() gives 732 error when input layer name contains forward slash char
Gotta do something with that metacharacter. Probably best to replace with an underscore, fc.replace('/','_') + '.lyr'. Could try to insert a backslash to escape the interpretation of that character but that could get messy.

Categories : Python

Im getting an error : Operator '==' cannot be applied to operands of type 'string' and 'char'
textBox1.Text.Split returns an array of strings and so your w is a string. Single quotes are used for chars and double quotes for strings. Therefore, it should be if (w == " ")

Categories : C#

Invalid types error when creating more than one "char*" variable in the same line
This is how C (and by extension Cython) type declarations have always worked. The line char *a, b; declares a as a char *, while b will be a char. To declare two character pointers, you can also werite char *a, *b; but I recommend getting into the habit of using separate lines, which tends to be less error-prone.

Categories : Python

unresolved external symbol error even though the function exists char*
The reason behind the linker not being able to match the methods is the mismatched Character Set option in projects General Properties page. The library project had this option set to Use Unicode Character Set and the application to Use Multi-Byte Character Set. Unifying the Character Set in both projects fixed this error.

Categories : C++

C - Error print char with scanf_s in Visual Studio 2012
You must specify the size of the input string or character in scanf_s. change scanf_s("%c",&b); to scanf_s("%c", &b, 1);

Categories : C

Unhandled Exception when converting const char to char
Both your contents of buff and buffA are in read-only memory of the process. You will actually need to new your buff like char* buff = new char[32]; This provides memory from the free-store and you can then strcat the string from buffA to buff. You should prefer strncat, though to avoid buffer-overruns and delete your buff eventually.

Categories : C++

Why doesn't C function with char** param set value of a pointer to char[] arg
The problem is that a pointer to an array is not compatible with a pointer to a pointer. They are different things. And it's a good thing too, because this is meant to catch errors like the one in your code. What you are doing is basically this: unsigned char szrecordid[28]; szrecordid = malloc(i * sizeof **value); You should be able to see the problem; you're trying to assign a pointer to an array.

Categories : C

why does passing char[] not work, but (deprecated conversion) char* does?
You have a problem in that you store pointers to local variables in the structure. In the case of the test_char2 array, it no longer exists once the get_struct function returns. This means that the pointer a_char2 no longer points to a valid string, and dereferencing this pointer is undefined behavior. The reason the first pointer works, is because it doesn't point to a local variable, it points to a string literal, and those are stored elsewhere in memory. When coding in C++, there is no longer a reason to use pointers or arrays for string, instead use the std::string class.

Categories : C++

how to convert c++ char read using "Marshal.ReadByte" to c# char?
Assuming the source char is using ASCII or Latin-1 (ISO 8859-1), in C# you'd do char ch = (char)Marshal.ReadByte(...);. This works because the ASCII and Latin-1 encodings are subsets of Unicode. A .NET char is a UTF-16 code unit, which will fit each of these fine with just a cast. If you think you'll deal with other source encodings, a better option may be to use Encoding.GetString() on a byte array. Keep in mind that some encodings require multiple units to encode a single code point (UTF-8, EUC-JP, Shift-JIS, etc.), so a single char may not be enough.

Categories : C#

Convert char* to jstring in JNI, when char* is passed using va_arg
You could just check JNI api documentation. E.g. Here. You will find: jstring NewStringUTF(JNIEnv *env, const char *bytes); So all you have to do it something like this: char *buf = (char*)malloc(10); strcpy(buf, "1234567890"); jstring jstrBuf = (*env)->NewStringUTF(env, buf);

Categories : Java

adding char[] to char** (string to a list of strings)
You can't copy strings using =, you have to use a function - such as the standard strcpy function. So: configurations[*multiplicity][start] = "a,"; should be: strcpy(configurations[*multiplicity][start], "a,"); And the same type of patterns elsewhere.

Categories : C



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.