825 Posted Topics

Member Avatar for Jsplinter

[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]

Member Avatar for Narue
0
233
Member Avatar for tikoti

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 << ':' …

Member Avatar for tikoti
0
2K
Member Avatar for anjoz

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> …

Member Avatar for arindam31
0
114
Member Avatar for senergy

I don't know about programatically (other than editing the registry) but you can use [icode]gpedit[/icode] to schedule these types of things.

Member Avatar for ktsangop
0
144
Member Avatar for tikoti

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.

Member Avatar for tikoti
0
276
Member Avatar for sandman64

[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 …

Member Avatar for L7Sqr
0
184
Member Avatar for gecko_dev

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...

Member Avatar for L7Sqr
-1
256
Member Avatar for Tupinambiss

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 …

Member Avatar for L7Sqr
0
205
Member Avatar for akshayinbox

[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 …

Member Avatar for lasitha2005d
-1
227
Member Avatar for sharathg.satya

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). …

Member Avatar for bajishareef
0
275
Member Avatar for sharma89bunty

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.

Member Avatar for venkata suresh
0
204
Member Avatar for xpartmgr

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& …

Member Avatar for mrnutty
0
128
Member Avatar for dilequeno

[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 …

Member Avatar for L7Sqr
0
886
Member Avatar for KAY111

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 …

Member Avatar for L7Sqr
0
173
Member Avatar for Vidgie65

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 …

Member Avatar for mike_2000_17
0
383
Member Avatar for anjoz

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 ' ' …

Member Avatar for thekashyap
0
137
Member Avatar for king03
Member Avatar for tikoti

[icode]namespace n1 { class c1; }[/icode] will not work for you? Whitespace is a user interface thing; C++ cares little for it.

Member Avatar for tikoti
0
198
Member Avatar for marcux
Member Avatar for orwell84
0
117
Member Avatar for super.mina

[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 …

Member Avatar for WaltP
1
131
Member Avatar for airbourne

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 …

Member Avatar for L7Sqr
0
722
Member Avatar for shadowscape

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]

Member Avatar for L7Sqr
0
1K
Member Avatar for jrock2004

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.

Member Avatar for L7Sqr
0
260
Member Avatar for Slavrix

Investigate how the [icode]*scanf[/icode] family of functions work. You must provide an address of a variable, not the variable itself.

Member Avatar for Slavrix
0
128
Member Avatar for Freude

[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.

Member Avatar for Freude
0
207
Member Avatar for chhabraamit

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.

Member Avatar for Narue
0
313
Member Avatar for Spillman

[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 …

Member Avatar for Spillman
0
237
Member Avatar for LesterTheGreat

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 …

Member Avatar for Schol-R-LEA
-1
239
Member Avatar for jenna123

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 …

Member Avatar for L7Sqr
0
80
Member Avatar for reza.adinata

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 = …

Member Avatar for reza.adinata
0
220
Member Avatar for vedro-compota

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).

Member Avatar for vedro-compota
0
114
Member Avatar for maayan7

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.

Member Avatar for L7Sqr
0
119
Member Avatar for DotNetUser

[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 …

Member Avatar for pseudorandom21
-1
2K
Member Avatar for theguitarist

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 …

Member Avatar for WaltP
0
494
Member Avatar for lochnessmonster

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.

Member Avatar for thekashyap
0
189
Member Avatar for ilovec++

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 …

Member Avatar for katmai539
0
2K
Member Avatar for ichigo_cool

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 …

Member Avatar for ichigo_cool
0
197
Member Avatar for focusedmm

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 …

Member Avatar for L7Sqr
0
118
Member Avatar for thetwig

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. …

Member Avatar for thetwig
0
208
Member Avatar for mwjones

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; …

Member Avatar for mwjones
0
173
Member Avatar for jory

[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.

Member Avatar for predator78
-1
105
Member Avatar for watery87

[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 …

Member Avatar for drkybelk
0
126
Member Avatar for NickPatton

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 …

Member Avatar for NickPatton
0
275
Member Avatar for Ahmed sunny

[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) …

Member Avatar for predator78
0
388
Member Avatar for ekailan

[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 …

Member Avatar for predator78
0
114
Member Avatar for Sonia11

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 …

Member Avatar for mrnutty
0
310
Member Avatar for Jsplinter

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 …

Member Avatar for Jsplinter
0
258
Member Avatar for vidit_X

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.

Member Avatar for pseudorandom21
0
242
Member Avatar for thekashyap

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 …

Member Avatar for thekashyap
3
629
Member Avatar for munitjsr2

[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 …

Member Avatar for mike_2000_17
0
2K

The End.