825 Posted Topics
Re: [icode]std::list[/icode] has a [icode]remove_if[/icode] method. [url=http://www.cplusplus.com/reference/stl/list/remove_if/]Check it out[/url] | |
Re: If I modify your code to use an object to do the output instead of putting the code inline you still have to call the manipulator functions but they happen every time. Consider[code]struct Formatter { void operator()(int r, int c) { std::cout.width(8); std::cout.setf(std::ios::fixed | std::ios::right); std::cout << r << ':' … | |
Re: You can easily get a pointer to that location through the [icode]str[/icode] variable. However, printing it without the remainder of the string will involve either a copy or modification of the original string to insert a null terminator. Copying the string would look something like (updating your original example):[code]#include <stdio.h> … | |
Re: I don't know about programatically (other than editing the registry) but you can use [icode]gpedit[/icode] to schedule these types of things. | |
Re: If I put in declarations for each of the functions ([icode]doIt[/icode] and [icode]accumSq[/icode]) above main the example compiles just fine for me. | |
Re: [QUOTE=sandman64;1596783]what about graph? I want to display its value in main() without sending it any parameters.[/QUOTE] [icode]graph[/icode] is a function. It is defined to take arguments. What are you expecting to see by looking at a function without invoking it? The best you are going to get is it's memory … | |
Re: So there is [url=http://www.android-x86.org/]androidx86[/url] which is a port of the Android to a PC platform. They have a TODO list that you could cherry-pick from if you were interested... | |
Re: Perhaps you meant something like [code]class Pet attr_accessor :name, :age, :gender end class Cat < Pet end [/code] where [icode]Cat[/icode] is a derivative of [icode]Pet[/icode]? What you have doesnt make very much sense. you create two distinct classes and then try to create another class (of the same name) and … | |
Re: [QUOTE=akshayinbox;1576292] I was wondering is their a way to determine a server's peak bandwidth? Say, if I use a Desktop model of IBM with 2 GB ram and 320GB HDD (just an arbitrary example), how much data transfer / PCs / network load it can handle (ALL TOUCH PANELS in … | |
Re: There was a similar question that become popular on SO recently. That version of the problem didnt allow loops or conditionals so the answers are mostly recursion based and [b]n[/b] happened to be fixed. If [b]n[/b] is user supplied some of the standard answers would be excluded (or need modification). … | |
Re: I'm guessing you may have meant something along the lines of:[code]switch(ch) { case '1': t=a+b;break; case '2': t=a-b;break; case '3': t=a*b;break; case '4': t=a/b;break; default:printf("invalid no:"); }[/code] Notice that the check is for the [i]character[/i] values not the integer values. | |
Re: Instead of using a pointer you can use a reference and get the same behavior. For instance, if the original signature of the function that compiled was[code] void createNewSurvey (Survey S) { ... }[/code] then you can make the following change and keep any modifications to [icode]S[/icode] within [icode]createNerSurvey[/icode][code]void createNewSurvey(Survey& … | |
Re: [QUOTE=firstPerson;1588618]Yes I know, but sorting cost nlogn using std::sort. So if a new element gets added, then its gonna cost him nlogn again before he could use binary search again. This is true for each elements he wants to add one by one[/QUOTE] As stated, the problem consists of read … | |
Re: To avoid the buffering effects on output streams you can use [icode]std::flush[/icode]. For example:[code]std::cout << a << ' ' << b << '\n' << std::flush[/code] If I recall correctly, [icode]std::endl[/icode] will do the same thing so if you replace [icode]'\n'[/icode] with [icode]std::endl[/icode] it should also work. N.B. That last part … | |
Re: I think it is good that you worked through this example by hand to see how to work with the containers; it is an invaluable experience, doing something by hand. Now that you are [mostly] done however, I'd suggest you have a look at something like [icode]std::random_shuffle[/icode] and how that … | |
Re: To add to what [b]thekashyap[/b] provided, you already have the count of arguments in the [icode]$#[/icode] variable and, in bash at least, you do not need to worry about multiple spaces so you can get away without both [icode]sed[/icode] calls. For instance:[code][ $# -ne `echo $* | tr ' ' … | |
Re: Change [icode]int sample[/icode] to [icode]char sample[/icode]. | |
Re: [icode]namespace n1 { class c1; }[/icode] will not work for you? Whitespace is a user interface thing; C++ cares little for it. | |
Re: Have you looked at creating a VLAN for these 10 computers? | |
Re: [QUOTE=abhimanipal;1576461]Basically this problem is identifying "strings of interest" log / sin / cos / (x) You use the strtok function to identify the start and end of these kind of strings[/QUOTE] [icode]strtok[/icode] modifies its target string. This is a [i]bad thing[/i] if you want to search multiple times over several … | |
Re: Why not just source the answer file? You could allow for any bash construct at that point. For instance File: script.sh[code]#!/bin/bash VAR="Original" if [[ $# -gt 0 && -e ${1} ]]; then . ${1} fi echo "VAR: ${VAR}"[/code]Which outputs just [icode]VAR: Original[/icode] when run with no parameters. BUt provided an … | |
Re: You can also fill a [icode]std::string[/icode] with all the valid characters you wish to support and generate random indexes into that string. Something like[code]std::string bucket = "abcdefghijklmnopqrstuvwxyz"; std::string uuid; for ( ... ) { uuid += bucket[rand() % bucket.size()]; }[/code] | |
Re: Are you sure that you are merging changes at the proper locations and then pushing to origin/master? Git is powerful but it takes some time to get fluent in its ways. | |
Re: Investigate how the [icode]*scanf[/icode] family of functions work. You must provide an address of a variable, not the variable itself. | |
Re: [QUOTE=Freude;1581396]What is the possible reason of such behaviour?[/QUOTE] gnuplot is line buffered and you do not send a newline to the application. Try:[code]fprintf( Gplt, "plot '/home/mk/nh1.dat' using 100 with lines\n");[/code]You may need to [icode]fflush (Gplt);[/icode] to ensure that the buffer is written to the application depending on your context. | |
Re: This is [i]highly[/i] system dependent and it is unlikely, even if we knew your system, that a 'simple example' would present itself without a significant amount of work. I'd suggest you google for I/O optimization for your particular platform. | |
Re: [QUOTE=Spillman;1579401][CODE] theCategory=arrCats[RandIndex]; //category I'm interested in getCatArrAndVals(colors); //I'm passing the hard-coded value of "colors" array //here but I really want to pass theCategory [/CODE][/QUOTE] The problem with that idea is that [icode]colors[/icode] is a [i]collection[/i] of things and [icode]theCategory[/icode] is just a thing. Your function needs to take either a … | |
Re: Realize Narue's position: this place (and others like it) draw many, many leeches. By leech I mean people who would rather copy and paste their homework into a forum and wait for a reply than attempt to do any work for themselves. The typical sign of this is a post … | |
Re: Well, you define the class initializer ([icode]def initialize(str)[/icode]) to take an argument in the base class. You do not change this behavior in the derived class. You can do one of the following to solve your problem: [code]class Sub < Generic def initialize @str = "" end end[/code] Which defined … | |
Re: With gcc (I'm not sure about other compilers since I think this is an extension) you can do this in one shot. For instance:[code]typedef struct _str { const char * s; int len; } str; typedef struct cs { str mouse; } cs; int main () { cs msg = … | |
Re: Each signal has an associated default handler (or action). In the case of [icode]SIGALRM[/icode] that action is to terminate the process. You can change this default action (for most signals) by registering a signal handler of your own or assigning [icode]SIG_IGN[/icode] (ignore). | |
Re: You define [icode]operator<<[/icode] for your class. For example:[code]struct Foo { friend std::ostream& operator<< (std::ostream& os, const Foo& f); };[/code]Then define that function as you would like. | |
Re: [QUOTE=DotNetUser;155774]I have to pass a pointer to a callback function. [/QUOTE] Is there any reason you can not use a functor? Whit a functor you have a great deal of flexibility in how you manage the context and you dont have to change the format or signature of your class … | |
Re: Consider [icode]std::cin[/icode] as a viewer over a large input stream where the stream is a sequence of bytes. What you get is a pointer at the current location in the stream and a way to manage about that point. [icode]cin[/icode] is [i]aware[/i] of types; this come from template magic and … | |
Re: Having a collection of Shapes would be terribly difficult if you has to have a separate container for each type of Shape you had. Casting to a Shape pointer allows you to store any type of Shape in a single container and still have it operate appropriately. | |
Re: Alternative to system: [icode]fork()[/icode] with [icode]exec*[/icode] on linux or [icode]CreateProcess[/icode] on Windows. [icode]popen[/icode] (a convenience wrapper around the previous method) Using [icode]getch()[/icode]: If you are looking to stop execution while you wait for user input any valid call that blocks on user input is valid. Not each method is necessarily … | |
Re: You may find it easier to implement your own [icode]operator[][/icode] instead of exposing the internals of your class. Something along the lines of: [code]class Inventory { std::vector< Potion * > potions; public: Inventory (size_type size) : potions(size) {} Potion*& operator[] (size_type index) { return potions[index]; } };[/code]Which allows for things … | |
Re: Well, given that you look like you want ARP and IPv4 traffic and you have a handle to the 'packet' returned by pcap (the raw array of bytes) you will need to get at the Ethernet header to first determine your type. Given a raw set of bytes you might … | |
Re: Casting to an int is a truncation. The fact that you are not clear on what is gettng truncated is a matter of precision. For instance, if I change your code to print the double to 20 decimal places here is the result I get: [code]Changing a double to int. … | |
Re: Considering the fact that you will need to recompile to accept new opcodes regardless is there any reason you can't generate this code with some scripting language and just use that? Something like: [code]int main () { /* ... */ switch (random_value) { #include "generated_switch_body.code" default: break; } return 0; … | |
Re: [QUOTE=jory;1569030]i want program that get a string from usre an display it reverse lke this input (noor) ouptut (roon)[/QUOTE] C++ [icode]std::reverse[/icode] works on strings as well as vectors. Please start a new thread if you have a question. | |
Re: [QUOTE=watery87;1568962]Hello, would like to ask about this problem im facing. [/QUOTE] When you create an array of fixed size you need to provide a constant value for the size. You are creating memory that is determined at compile time and not runtime so the size needs to be fixed and … | |
Re: Try making the following edits to your code:[code] fprintf (stderr, "[Child] Tring to accept...\n"); client_sockfd = accept(server_sockfd, (struct sockaddr*)&client_address, &client_len); fprintf (stderr, "[Child] done!\n");[/code] and [code] fprintf (stderr, "[Parent] waiting for child...\n"); pid_child=wait(&stat_val); fprintf (stderr, "[Parent] done waiting\n");[/code] In the parent, you are waiting for the child to exit while … | |
Re: [QUOTE=Uzair Malik;1567884]i also need help with this..... logically this is all correct but i don't know how to convert it into the coding and make exact condition help me out plz[/QUOTE] A recursive function calls itself usually moving toward some halting condition [code]void function(int arg) { if (arg > 0) … | |
Re: [QUOTE=ekailan;1563568]Is it possible to use file to increase the memory available. for example: if we ahve code need 1 GB RAM to be work is it possible to run it in a system with 512MB RAM and use a file to allocate the rest of the memory needed.[/QUOTE] You can … | |
Re: The point of a template is to remove the need to implement each of the [icode]reverseInt[/icode] and [icode]reverseString[/icode] functions and allow for a single function that operates properly depending on the type of the template. Try working with the following example which builds a similar class and uses it to … | |
Re: How do you expect to split up the sets of numbers? subset is a pretty generic topic. [edit] Sorry, I missed the part where you said 'distance from one another' :) Still, splitting on a distance is rather trivial: sort and look for gaps greater than a specified distance. You … | |
Re: Please describe 'not able to run it'. I compiled your code and ran it with the following input[code]1 2345431[/code]and got in return[code]2345432[/code]As I would expect. | |
Re: While I think that using the placement new operator in the appropriate place is a powerful tool, I think that your example takes away from any of that. Most of your example deals with the mechanics of defining and construction your pixel matrices. Only a very small portion of the … | |
Re: [icode]std::find_if[/icode] certainly will do what you want. However, realize that it only finds the first occurrence over the range you provide. If you want to delete multiple values you will have to search until there is no match. Here is an example of finding and deleting a single value:[code] #include … |
The End.