Search Results

Search found 6123 results on 245 pages for 'unsigned char'.

Page 5/245 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Java: Checking contents of char variable with if condition

    - by Troy
    Hello, I have a char variable that is supposed to contain either a Y,y,n or N character, I want to test if it does not contain it, then display an error message and exit the program. This is the code I am using; if (userDecision != 'Y' || userDecision != 'y' || userDecision != 'n' || userDecision != 'N') { System.out.println("Error: invalid input entered for the interstate question"); System.exit(0); } Irregardless of what is in the variable it always returns true and executes the command to exit the program, what am I doing wrong?

    Read the article

  • How do I output an individual character when using char *[] = "something"

    - by Matt
    I've been playing with pointers to better understand them and I came across something I think I should be able to do, but can't sort out how. The code below works fine - I can output "a", "dog", "socks", and "pants" - but what if I wanted to just output the 'o' from "socks"? How would I do that? char *mars[4] = { "a", "dog", "sock", "pants" }; for ( int counter = 0; counter < 4; counter++ ) { cout << mars[ counter ]; } Please forgive me if the question is answered somewhere - there are 30+ pages of C++ pointer related question, and I spent about 90 minutes looking through them, as well as reading various (very informative) articles, before deciding to ask.

    Read the article

  • How do I convert a single char in string to an int

    - by Guest
    Keep in mind, if you choose to answer the question, I am a beginner in the field of programming and may need a bit more explanation than others as to how the solutions work. Thank you for your help. My problem is that I am trying to do computations with parts of a string (consisting only of numbers), but I do not know how to convert an individual char to an int. The string is named "message". for (int place = 0; place < message.size(); place++) { if (secondPlace == 0) { cout << (message[place]) * 100 << endl; } } Thank you.

    Read the article

  • C++ sort array of char pointes

    - by user69514
    Can you tell me what's wrong with my method? I ends up putting the same thing everywhre and it's actually not sorting. void sortArrays(){ int i, j; for(i=0; i<counter; i++){ for( j=0; j<i; j++){ if( strcmp(title_arr[i], title_arr[j]) < 0){ char* title_temp = title_arr[i]; title_arr[j] = title_temp; } } }

    Read the article

  • C++ sort array of char pointers

    - by user69514
    Can you tell me what's wrong with my method? I ends up putting the same thing everywhre and it's actually not sorting. void sortArrays(){ int i, j; for(i=0; i<counter; i++){ for( j=0; j<i; j++){ if( strcmp(title_arr[i], title_arr[j]) < 0){ char* title_temp = title_arr[i]; title_arr[j] = title_temp; } } }

    Read the article

  • Check and avoid if a char is being entered in a int

    - by John
    Hi.... This is a exremely stupid question but i need help with this.... I'm trying to make a small program that i made robust and needed some help with tht.... int num1; int num2 = 0; System.out.print("Enter number 1: "); num1 = kb.nextInt(); while(num2<num1) { System.out.print("Enter number 2: "); num2 = kb.nextInt(); } Number 2 has to be greater than number 1 Also i want the program to automatically check and ignore if the user enters a char instead of an int... Cause right now when a user enters lets say "r" instead of a number the program just exists....

    Read the article

  • char '0x8' what character is this?

    - by OHHAI
    I have a large amount of data in a database. When I attempt to read a certain portion of the data and generate some xml and send it to a webservice I get the following exception... The char '0x8' in 'java.lang.IllegalArgumentException'. I'm guessing it is some bad data, as it has worked perfectly for about 7 months but now some user uploaded some new data that seems to have some issues. Anyone know what character this is so I can just run a sql query and clean it from the db? Thanks in advance.

    Read the article

  • How to convert char to LPCTSTR (MFC)?

    - by Shark
    Is there any way to do this? This is what I am trying to do: char s[] = { 'a', 'b' }; label.SetWindowTextW(s[1]); label is CStatic typed, _UNICODE is defined. Any help would be appreciated. UPD: Tried to use CString(s[1]), it works for ASCII characters but others won't work. E. g. for the ? it returns |.

    Read the article

  • How to convert an NSString to an unsigned int in Cocoa?

    - by Dave Gallagher
    My application gets handed an NSString containing an unsigned int. NSString doesn't have an [myString unsignedIntegerValue]; method. I'd like to be able to take the value out of the string without mangling it, and then place it inside an NSNumber. I'm trying to do it like so: NSString *myUnsignedIntString = [self someMethodReturningAString]; NSInteger myInteger = [myUnsignedIntString integerValue]; NSNumber *myNSNumber = [NSNumber numberWithInteger:myInteger]; // ...put |myNumber| in an NSDictionary, time passes, pull it out later on... unsigned int myUnsignedInt = [myNSNumber unsignedIntValue]; Will the above potentially "cut off" the end of a large unsigned int since I had to convert it to NSInteger first? Or does it look OK to use? If it'll cut off the end of it, how about the following (a bit of a kludge I think)? NSString *myUnsignedIntString = [self someMethodReturningAString]; long long myLongLong = [myUnsignedIntString longLongValue]; NSNumber *myNSNumber = [NSNumber numberWithLongLong:myLongLong]; // ...put |myNumber| in an NSDictionary, time passes, pull it out later on... unsigned int myUnsignedInt = [myNSNumber unsignedIntValue]; Thanks for any help you can offer! :)

    Read the article

  • Why do I get errors when using unsigned integers in an expression with C++?

    - by neuviemeporte
    Given the following piece of (pseudo-C++) code: float x=100, a=0.1; unsigned int height = 63, width = 63; unsigned int hw=31; for (int row=0; row < height; ++row) { for (int col=0; col < width; ++col) { float foo = x + col - hw + a * (col - hw); cout << foo << " "; } cout << endl; } The values of foo are screwed up for half of the array, in places where (col - hw) is negative. I figured because col is int and comes first, that this part of the expression is converted to int and becomes negative. Unfortunately, apparently it doesn't, I get an overflow of an unsigned value and I've no idea why. How should I resolve this problem? Use casts for the whole or part of the expression? What type of casts (C-style or static_cast<...)? Is there any overhead to using casts (I need this to work fast!)? EDIT: I changed all my unsigned ints to regular ones, but I'm still wondering why I got that overflow in this situation.

    Read the article

  • Bewildering SegFault involving STL sort algorithm.

    - by just_wes
    Hello everybody, I am completely perplexed at a seg fault that I seem to be creating. I have: vector<unsigned int> words; and global variable string input; I define my custom compare function: bool wordncompare(unsigned int f, unsigned int s) { int n = k; while (((f < input.size()) && (s < input.size())) && (input[f] == input[s])) { if ((input[f] == ' ') && (--n == 0)) { return false; } f++; s++; } return true; } When I run the code: sort(words.begin(), words.end()); The program exits smoothly. However, when I run the code: sort(words.begin(), words.end(), wordncompare); I generate a SegFault deep within the STL. The GDB back-trace code looks like this: #0 0x00007ffff7b79893 in std::string::size() const () from /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/libstdc++.so.6 #1 0x0000000000400f3f in wordncompare (f=90, s=0) at text_gen2.cpp:40 #2 0x000000000040188d in std::__unguarded_linear_insert<__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, unsigned int, bool (*)(unsigned int, unsigned int)> (__last=..., __val=90, __comp=0x400edc <wordncompare(unsigned int, unsigned int)>) at /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algo.h:1735 #3 0x00000000004018df in std::__unguarded_insertion_sort<__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, bool (*)(unsigned int, unsigned int)> (__first=..., __last=..., __comp=0x400edc <wordncompare(unsigned int, unsigned int)>) at /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algo.h:1812 #4 0x0000000000402562 in std::__final_insertion_sort<__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, bool (*)(unsigned int, unsigned int)> (__first=..., __last=..., __comp=0x400edc <wordncompare(unsigned int, unsigned int)>) at /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algo.h:1845 #5 0x0000000000402c20 in std::sort<__gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int, std::allocator<unsigned int> > >, bool (*)(unsigned int, unsigned int)> (__first=..., __last=..., __comp=0x400edc <wordncompare(unsigned int, unsigned int)>) at /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algo.h:4822 #6 0x00000000004012d2 in main (argc=1, args=0x7fffffffe0b8) at text_gen2.cpp:70 I have similar code in another program, but in that program I am using a vector instead of vector. For the life of me I can't figure out what I'm doing wrong. Thanks!

    Read the article

  • Passing char * into fopen with C.

    - by Rhys
    Hey there, I'm writing a program that passes data from a file into an array, but I'm having trouble with fopen (). It seems to work fine when I hardcode the file path into the parameters (eg fopen ("data/1.dat", "r");) but when I pass it as a pointer, it returns NULL. Note that line 142 will print "data/1.dat" if entered from command line so parse_args () appears to be working. 132 int 133 main(int argc, char **argv) 134 { 135 FILE *in_file; 136 int *nextItem = (int *) malloc (sizeof (int)); 137 set_t *dictionary; 138 139 /* Parse Arguments */ 140 clo_t *iopts = parse_args(argc, argv); 141 142 printf ("INPUT FILE: %s.\n", iopts->input_file); /* This prints correct path */ 143 /* Initialise dictionary */ 144 dictionary = set_create (SET_INITAL_SIZE); 145 146 /* Use fscanf to read all data values into new set_t */ 147 if ((in_file = fopen (iopts->input_file, "r")) == NULL) 148 { 149 printf ("File not found...\n"); 150 return 0; 151 } Thanks! Rhys

    Read the article

  • Trying to compile a linux-based app on Mac OS X

    - by Scott
    I'm just trying to compile the linux-based FCEUX (NES emulator) on my mac, OS X 10.5 Leopard. I got all the dependencies (SDL, GTK+ 2) going and everything but of all things this is now my problem: Undefined symbols: "_compress", referenced from: SaveSnapshot() in video.o "_gzclose", referenced from: FCEU_fopen(char const*, char const*, char*, char*, int, char const**)in file.o "_crc32", referenced from: CalcCRC32(unsigned int, unsigned char*, unsigned int)in crc32.o _unzReadCurrentFile in unzip.o _unzReadCurrentFile in unzip.o "_uncompress", referenced from: NetplayUpdate(unsigned char*)in netplay.o FCEUSS_LoadFP(EMUFILE*, ENUM_SSLOADPARAMS) in state.o "_compress2", referenced from: FCEUNET_SendFile(unsigned char, char*)in netplay.o FCEUSS_SaveMS(EMUFILE*, int) in state.o "_inflateEnd", referenced from: _unzCloseCurrentFile in unzip.o "_inflate", referenced from: _unzReadCurrentFile in unzip.o "inflateInit2", referenced from: _unzOpenCurrentFile in unzip.o "_gzgetc", referenced from: FCEU_fopen(char const*, char const*, char*, char*, int, char const**)in file.o "_gzopen", referenced from: FCEU_fopen(char const*, char const*, char*, char*, int, char const**)in file.o "_gzread", referenced from: FCEU_fopen(char const*, char const*, char*, char*, int, char const**)in file.o "_gzseek", referenced from: FCEU_fopen(char const*, char const*, char*, char*, int, char const*)in file.o ld: symbol(s) not found collect2: ld returned 1 exit status scons: ** [src/fceux] Error 1 scons: building terminated because of errors. Those are zlib functions. It seems like it is loading the zlib.h ok, but the symbols aren't being linked in? Just to make sure I downloaded the latest zlib and did a make install, no help. I have no clue what's going on here, it seems like it should be pretty basic, that library is nothing special. Help would be appreciated. Thanks.

    Read the article

  • Socket in C: recv overwrite a char[]

    - by Possa
    Hi all, I'm trying to make a little client-server script like many others that I've done in the past. But in this one I have a problem. It is better if I post the code and the output it give me. Code: #include <mysql.h> //not important now #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <string.h> //constant definition #define SERVER_PORT 2121 #define LINESIZE 21 //global var definition char victim_ip[LINESIZE], file_write[LINESIZE], hacker_ip[LINESIZE]; //function void leggi (int); //not use now for debugging purpose //void scriviDB (); //not important now main () { int sock, client_len, fd; struct sockaddr_in server, client; // transport end point if((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("system call socket fail"); exit(1); } server.sin_family = AF_INET; server.sin_addr.s_addr = inet_addr("10.10.10.1"); server.sin_port = htons(SERVER_PORT); // binding address at transport end point if (bind(sock, (struct sockaddr *)&server, sizeof server) == -1) { perror("system call bind fail"); exit(1); } //fprintf(stderr, "Server open: listening.\n"); listen(sock, 5); /* managae client connection */ while (1) { client_len = sizeof(client); if ((fd = accept(sock, (struct sockaddr *)&client, &client_len)) < 0) { perror("accepting connection"); exit(1); } strcpy(hacker_ip, inet_ntoa(client.sin_addr)); printf("1 %s\n", hacker_ip); //debugging purpose //leggi(fd); ////////////////////////// //receive client recv(fd, victim_ip, LINESIZE, 0); victim_ip[sizeof(victim_ip)] = '\0'; printf("2 %s\n", hacker_ip); //debugging purpose recv(fd, file_write, LINESIZE, 0); file_write[sizeof(file_write)] = '\0'; printf("3 %s\n", hacker_ip); //debugging purpose printf("%s@%s for %s\n", file_write, victim_ip, hacker_ip); //send to client send(fd, hacker_ip, 40, 0); //now is hacker_ip for debug ///////////////////////// close(fd); }//end while exit(0); } //end main Client send string: ./send -i 10.10.10.4 -f filename.ext so the script send -i (IP) and -f (FILE) at the server. Here's my output server side: 1 10.10.10.6 2 10.10.10.6 3 [email protected] for As you can see the printf(3) and the printf(ip,file,ip) fail. I don't know how and where but someone overwrite my hacker_ip string. Thanks for your help! :)

    Read the article

  • how to get rid off garbage in array of chars?

    - by fang_dejavu
    hi, I'm writing a C program but I keep having problems with my array of chars. I keep getting garbage when I print it using prinf. here is an example of what I get when I print it: char at t.symbol is Aôÿ¿ char at tabl[0].symbol is A char at tabl[1].symbol is a char at tabl[2].symbol is a char at tabl[3].symbol is d char at tabl[4].symbol is e char at tabl[5].symbol is f char at tabl[6].symbol is g char at tabl[7].symbol is h char at tabl[8].symbol is i char at tabl[9].symbol is x char at t[0].symbol is a0AÃ char at t[1].symbol is b)@Ã4 char at t[2].symbol is ckU* char at t[3].symbol is Aôÿ¿ char at t[4].symbol is gØ could someone tell me how to get rid off the garbage in the array of chars? here is my code #define MAX 100 #ifndef SYMBSIZE #define SYMBSIZE 1 #endif typedef struct tableme { char symbol[SYMBSIZE]; int value; int casenmbr; int otherinfo; }tabletype; int main(int argc, char **argv) { tabletype t[MAX]; t[3].symbol[0] = 'A'; t[0].value=1; t[0].casenmbr = 7; t[0].otherinfo = 682; tabletype tabl[MAX]; tabl[0].value = 1; tabl[0].symbol[0] = 'A'; tabl[1].value = 11; tabl[1].symbol[0]= 'a'; tabl[2].value = 12; tabl[2].symbol[0] = 'a'; tabl[3].value = 13; tabl[3].symbol[0] = 'd'; tabl[4].value = 14; tabl[4].symbol[0] = 'e'; tabl[5].value = 15; tabl[5].symbol[0] = 'f'; tabl[6].value = 16; tabl[6].symbol[0] = 'g'; tabl[7].value = 17; tabl[7].symbol[0] = 'h'; tabl[8].symbol[0] = 'i'; tabl[9].symbol[0] = 'x'; t[1].symbol[0] = 'b'; t[0].symbol[0]= 'a'; t[2].symbol[0]= 'c'; t[4].symbol[0]= 'g'; printf("char at t.symbol is %s \n", t[3].symbol); for( x=0;x<10;x++) { printf("char at tabl[%d].symbol is %s \n",x, tabl[x].symbol); } int j; for(j = 0; j<5;j++) { printf("char at t[%d].symbol is %s \n",j, t[j].symbol); } return 0; }

    Read the article

  • How to determine 2D unsigned short pointers array length in c++

    - by tuman
    Hello, I am finding it difficult to determine the length of the columns in a 2D unsigned short pointer array. I have done memory allocation correctly as far as I know. and can print them correctly. plz see the following code segment: int number_of_array_index_required_for_pointer_abc=3; char A[3][16]; strcpy(A[0],"Hello"); strcpy(A[1],"World"); strcpy(A[2],"Tumanicko"); cout<<number_of_array_index_required_for_pointer_abc*sizeof(unsigned short)<<endl; unsigned short ** pqr=(unsigned short **)malloc(number_of_array_index_required_for_pointer_abc*sizeof(unsigned short)); for(int i=0;i<number_of_array_index_required_for_pointer_abc;i++) { int ajira = strlen(A[i])*sizeof(unsigned short); cout<<i<<" = "<<ajira<<endl; pqr[i]=(unsigned short *)malloc(ajira); cout<<"alocated pqr[i]= "<<sizeof pqr<<endl; int j=0; for(j=0;j<strlen(A[i]);j++) { pqr[i][j]=(unsigned short)A[i][j]; } pqr[i][j]='\0'; } for(int i=0;i<number_of_array_index_required_for_pointer_abc;i++) { //ln= (sizeof pqr[i])/(sizeof pqr[0]); //cout<<"Size of pqr["<<i<<"]= "<<ln<<endl; // I want to know the size of the columns i.e. pqr[i]'s length instead of finding '\0' for(int k=0;(char)pqr[i][k]!='\0';k++) cout<<(char)pqr[i][k]; cout<<endl; }

    Read the article

  • Java char literal to C# char literal

    - by Kristoffersen
    Hi. I am maintaining some Java code that I am currently converting to C#. The Java code is doing this: sendString(somedata + '\000'); And in C# I am trying to do the same: sendString(somedata + '\000'); But on the '\000' VS2010 tells me that "Too many characters in character literal". How can I use '\000' in C#? I have tried to find out what the character is, but it seems to be " " or some kind of newline-character. Do you know anything about the issue? Thanks!

    Read the article

  • Getting a cryptic error on my simple Java program, comparing char[i] to a string.

    - by Sergio Tapia
    public static void ejemplosString(String palabra){ char[] letras = palabra.toCharArray(); int contadorVocales = 0; for (int i = 0; i < letras.length; i++) { if (char[i] == 'a') { contadorVocales++; } if (char[i] == "e") { contadorVocales++; } if (char[i] == "i") { contadorVocales++; } if (char[i] == "o") { contadorVocales++; } if (char[i] == "u") { contadorVocales++; } } } Getting the error on every If statement. Any guidance?

    Read the article

  • traverse a string char by char javascript

    - by mikeandike
    function SimpleSymbols(str) { var letter =['a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; var newstr = ""; for (var i = 0; i<str.length; i++){ if (str.charAt(i).toLowerCase() in letter){ newstr += "M"; } else{ newstr += "X"; } } return newstr; } If str is "Argument goes here" it returns XXXXXXXXX. WHy doesn't it return MMMMMMMMMM?

    Read the article

  • Question about memory allocation when initializing char arrays in C/C++.

    - by Carlos Nunez
    Before anything, I apologize if this question has been asked before. I am programming a simple packet sniffer for a class project. For a little while, I ran into the issue where the source and destination of a packet appeared to be the same. For example, the source and destination of an Ethernet frame would be the same MAC address all of the time. I custom-made ether_ntoa(char *) because Windows does not seem to have ethernet.h like Linux does. Code snippet is below: char *ether_ntoa(u_char etheraddr[ETHER_ADDR_LEN]) { int i, j; char eout[32]; for(i = 0, j = 0; i < 5; i++) { eout[j++] = etheraddr[i] >> 4; eout[j++] = etheraddr[i] & 0xF; eout[j++] = ':'; } eout[j++] = etheraddr[i] >> 4; eout[j++] = etheraddr[i] & 0xF; eout[j++] = '\0'; for(i = 0; i < 17; i++) { if(eout[i] < 10) eout[i] += 0x30; else if(eout[i] < 16) eout[i] += 0x57; } return(eout); } I solved the problem by using malloc() to have the compiler assign memory (i.e. instead of char eout[32], I used char * eout; eout = (char *) malloc (32);). However, I thought that the compiler assigned different memory locations when one sized a char-array at compile time. Is this incorrect? Thanks! Carlos Nunez

    Read the article

  • linker error when using tr1::regex

    - by Max
    Hello. I've got a program that uses tr1::regex, and while it compiles, it gives me very verbose linker errors. Here's my header file MapObject.hpp: #include <iostream> #include <string> #include <tr1/regex> #include "phBaseObject.hpp" using std::string; namespace phObject { class MapObject: public phBaseObject { private: string color; // must be a hex string represented as "#XXXXXX" static const std::tr1::regex colorRX; // enforces the rule above public: void setColor(const string&); (...) }; } Here's my implementation: #include <iostream> #include <string> #include <tr1/regex> #include "MapObject.hpp" using namespace std; namespace phObject { const tr1::regex MapObject::colorRX("#[a-fA-F0-9]{6}"); void MapObject::setColor(const string& c) { if(tr1::regex_match(c.begin(), c.end(), colorRX)) { color = c; } else cerr << "Invalid color assignment (" << c << ")" << endl; } (...) } and now for the errors: max@max-desktop:~/Desktop/Development/CppPartyHack/PartyHack/lib$ g++ -Wall -std=c++0x MapObject.cpp /tmp/cce5gojG.o: In function std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)': MapObject.cpp:(.text._ZNSt3tr111basic_regexIcNS_12regex_traitsIcEEEC1EPKcj[std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)]+0x61): undefined reference tostd::tr1::basic_regex ::_M_compile()' /tmp/cce5gojG.o: In function bool std::tr1::regex_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11u>)': MapObject.cpp:(.text._ZNSt3tr111regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcEEEEbT_S8_RKNS_11basic_regexIT0_T1_EESt6bitsetILj11EE[bool std::tr1::regex_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11u>)]+0x53): undefined reference tobool std::tr1::regex_match<__gnu_cxx::__normal_iterator, std::allocator , std::allocator, std::allocator , char, std::tr1::regex_traits (__gnu_cxx::__normal_iterator, std::allocator , __gnu_cxx::__normal_iterator, std::allocator , std::tr1::match_results<__gnu_cxx::__normal_iterator, std::allocator , std::allocator, std::allocator &, std::tr1::basic_regex const&, std::bitset<11u)' collect2: ld returned 1 exit status I can't really make heads or tails of this, except for the undefined reference to std::tr1::basic_regex near the beginning. Anyone know what's going on?

    Read the article

  • Why does operator<< not work with something returned by operator-?

    - by Felix
    Here's a small test program I wrote: #include <iostream> using namespace std; class A { public: int val; A(int _val=0):val(_val) { } A operator+(A &a) { return A(val + a.val); } A operator-(A &a) { return A(val - a.val); } friend ostream& operator<<(ostream &, A &); }; ostream& operator<<(ostream &out, A &a) { out<<a.val; return out; } int main() { A a(3), b(4), c = b - a; cout<<c<<endl; // this works cout<<(b-a)<<endl; // this doesn't return 0; } I can't seem to get why the line marked "this works" works and the one marked "this doesn't" doesn't. When I try to compile the program with the cout<<(b-a); line, here's what I get: [felix@the-machine C]$ g++ test.cpp test.cpp: In function ‘int main()’: test.cpp:26:13: error: no match for ‘operator<<’ in ‘std::cout << b.A::operator-(((A&)(& a)))’ /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:108:7: note: candidates are: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:117:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>, std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:127:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:165:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:169:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:173:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/bits/ostream.tcc:91:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:180:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/bits/ostream.tcc:105:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:191:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:200:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:204:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:209:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:213:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:221:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:225:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/bits/ostream.tcc:119:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>] test.cpp:18:11: note: std::ostream& operator<<(std::ostream&, A&) [felix@the-machine C]$ Quite nasty.

    Read the article

  • Why does this C++ code result in a segmentation fault?

    - by user69514
    I keep getting a segmentation fault when the readAuthor() method is called. Does anybody know why this happens? I am supposed to use dynamic arrays, I know this would be so easy if I was using static array. #include <iostream> #include <string> #include <cstring> #include <cstdlib> using namespace std; /** declare arrays **/ int* isbnArr = new int[25]; char* authorArr = new char[25]; char* publisherArr = new char[25]; char* titleArr = new char[25]; int* editionArr = new int[25]; int* yearArr = new int[25]; int* pagesArr = new int[25]; float* retailPriceArr = new float[25]; float* discountedPriceArr = new float[25]; int* stockArr = new int[25]; /** function prototypes **/ int readIsbn(); char* readAuthor(); char* readPublisher(); char* readTitle(); int readEdition(); int readYear(); int readPages(); float readMsrp(); float readDiscountedPrice(); int readStockAmount(); void readonebook(int* isbn, char* author, char* title, char* publisher, int* edition, int* year, int* pages, float* msrp, float* discounted, int* inventory); int main() { bool stop = false; //flag when to stop loop int ind = 0; //index for current book while( !stop ){ cout << "Add book: press A: "; cout << "another thing here "; char choice; cin >> choice; if( choice == 'a' || choice == 'A' ){ readonebook(&isbnArr[ind], &authorArr[ind], &titleArr[ind], &publisherArr[ind], &editionArr[ind], &yearArr[ind], &pagesArr[ind], &retailPriceArr[ind], &discountedPriceArr[ind], &stockArr[ind]); test(&authorArr[ind]); ind++; } } return 0; } /** define functions **/ int readIsbn(){ int isbn; cout << "ISBN: "; cin >> isbn; return isbn; } char* readAuthor(){ char* author; cout << "Author: "; cin >> author; return author; } char* readPublisher(){ char* publisher = NULL; cout << "Publisher: "; cin >> publisher; return publisher; } char* readTitle(){ char* title = NULL; cout << "Title: "; cin >> title; return title; } int readEdition(){ int edition; cout << "Edition: "; cin >> edition; return edition; } int readYear(){ int year; cout << "Year: "; cin >> year; return year; } int readPages(){ int pages; cout << "Pages: "; cin >> pages; return pages; } float readMsrp(){ float price; cout << "Retail Price: "; cin >> price; return price; } float readDiscountedPrice(){ float price; cout << "Discounted Price: "; cin >> price; return price; } int readStockAmount(){ int amount; cout << "Stock Amount: "; cin >> amount; return amount; } void readonebook(int* isbn, char* author, char* title, char* publisher, int* edition, int* year, int* pages, float* msrp, float* discounted, int* inventory){ *isbn = readIsbn(); author = readAuthor(); title = readTitle(); publisher = readPublisher(); *edition = readEdition(); *year = readYear(); *pages = readPages(); *msrp = readMsrp(); *discounted = readDiscountedPrice(); *inventory = readStockAmount(); }

    Read the article

  • Pronunciation of "char"

    - by Zannjaminderson
    I know there's another question on here already about pronunciation here, but it's got a whole list of programming terms. I'm just interested in finding out how everybody pronounces just one thing - "char". I personally like "care" as in the first syllable of "character", since that's what it represents, but in past experience I've found there are far more people who say "char" as in "char-broiled", and some who say "car". Sorry to start a holy war, but I'm curious.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >