Hi All, In below code i am getting ouput of process (based on name) memory and cpu utilization % using command "ps -C gnome-terminal -o %cpu,%mem | tail -n +2" .Here gnome-terminal is name of process for that i am printing these values. Now i want to implement the same by reading all the process name dynamically and passing to input to my function GetStdoutFromCommand instead of hardcoding in command. Can somebody throw some light on this , how to achieve the same by referring below code. so basicallly in my command instead of giving hardcoded process name [i.e. gnome-terminal] …

Member Avatar
+0 forum 0

Hi All, I have to implement string class and write a program to perform string manipulation in Mystring class. input: "he is going to school" output Case 1: (n=1) He school to going is Case 2: (n=2) He is school to going Case 3:(n=5) No changes Case 4 n<=0 school to going is He. int main() { char str[100]= ""; int n; //Take input str and n from console MyString obj (str); obj.manipulate(n);//Actual logic obj.display();// This will print output return 0; } can anybody throw some light on approach to for case 1 and case 2.

Member Avatar
Member Avatar
+0 forum 13

Hi, Guys i just wanted to know whether set store elements in specific order or it contains unordered elements only. As per c++ specification http://www.cplusplus.com/reference/set/set/?kw=set Sets are containers that store unique elements following a specific order. As per my knowledge they are not ordered in the sense that you can't enforce an arbitrary order by placing an arbitrary element in an arbitrary position. it is usually implemented as a red-black tree and i believe due to this it is not possible to place and arbitrary element in an arbitrary position. In java the Set interface does not provide any ordering …

Member Avatar
Member Avatar
+0 forum 4

Hi, In below function i am not able to figure out why predicate function cmp_str can't be used with for_each algoritham while using this algoritham with map. #include <iostream> #include <map> #include <utility> using namespace std; struct cmp_str { bool operator()(string a, string b) { return a.compare(b)<0; } }; int main() { map<string, int > Employees; // Examples of assigning Map container contents // 1) Assignment using array index notation Employees["Mike C."] = 5234; Employees["Charlie M."] = 3374; // 2) Assignment using member function insert() and STL pair Employees.insert(std::pair<string ,int>("David D.",1923)); // 3) Assignment using member function insert() and "value_type()" …

Member Avatar
Member Avatar
+0 forum 7

Hello all! I am trying to take a string that has mixed uppercase and lowercase chars and then convert it to lowercase. I am doing the following line of C++ code: transform(theReadMessage.begin(),theReadMessage.end(),theReadMessage.begin(),theReadMessage.end(),::tolower); //theReadMessage is a string to convert to lowercase and my C++ xCode debugger gives me this message `Too many arguments to function call, expected 1, have 2.` What am I doing wrong? Thanks in advance!!

Member Avatar
Member Avatar
+0 forum 7

Hi, I have the following map : listOfPolicyRuleInfo CPCRF::m_mlistOfCliConfiguredPolicyRules; where typedef map<string, PolicyRuleInfo> listOfPolicyRuleInfo; where PolicyRuleInfo is a struct struct PolicyRuleInfo{ BearerQoSInfo stBearerQoS; TFTInfo stTFTInfo; PolicyRuleInfo(){}; PolicyRuleInfo( BearerQoSInfo const& qos, TFTInfo const& tft) : stBearerQoS(qos), stTFTInfo(tft) { } }; listOfPolicyRuleInfo m_mlistOfCliConfiguredPolicyRules = boost::assign::map_list_of("PolicyRule_Fred", PolicyRuleInfo( BearerQoSInfo(9), TFTInfo())) ("PolicyRule_Voice_C", PolicyRuleInfo( BearerQoSInfo(5), TFTInfo())) ("PolicyRule_Voice_U", PolicyRuleInfo( BearerQoSInfo(1), TFTInfo())); Above are the data strutures. Now within the code somewhere , listOfPolicyRuleInfo::iterator it = m_mlistOfCliConfiguredPolicyRules.find("PolicyRule_Fred"); I get error when i try to print the contents of it. on gdb i see the list (gdb)p m_mlistOfCliConfiguredPolicyRules ["PolicyRule_Fred"] = {stBearerQoS = {nQCI = 9, nMaxUlBitRate = 0, nMaxDlBitRate …

Member Avatar
Member Avatar
+0 forum 3

**Okay this is my first post and I am quite excited that how it will be recieved by the community. I have a long experience in C++ programming but never been a part of any community hence I believe that as a tyro, my mistakes will be ignored.** This post will be about a problem statement that got in my college exams during my engineering. It was a question of an assignment. The question was as follows *Write the most efficient program to print Fibonacci series up to the value given during runtime and also store the values in a …

Member Avatar
Member Avatar
+0 forum 4

Hello, I have a basic c++ STL question. I have an octet array class (legacy). Now lets say the octet array has the following contents: array[0]=00 array[1]=01 array[2]=30 array[3]=01 array[4]=114 The key we need to generate from the above array should match ["00130-1-114"] Whats the best way to get this from the above array. In the legacy code, there is way to convert, but is using lot of magic numbers everywhere, it is quite not readable.. ~pdk

Member Avatar
Member Avatar
+0 forum 1

If I (have to) use C/C++, I'm mostly working on time-critical or real-time applications. Examples are OpenGL texture Streaming (Example: Streaming Satalite Data on planet surface in realtime: https://www.youtube.com/watch?v=ws2ra5MvDi4) or real-time PSM audio maonpulation (Example: Automatic tuning a guitar to a C64= SID tremolo: http://www.yousry.de/audio-example-real-time-tune-detection-tuning-auto-tuning/). During development I'm using "**-O0 -g**" as compiler options to enable *dwarf* debugging information. But as result, STL becomes unusable slow (missing loop unroling, vec optimizations etc.) In these cases I write code like: #ifndef DEBUG // deque too slow std::deque<float> inFIFO; std::deque<float> outFIFO; #else float* inFIFO; float* outFIFO; #endif to avoid later discussions "*Why …

Member Avatar
Member Avatar
+0 forum 10

Hello programmers! After covering the basics of STL, I decided to complete the following assignment: `Write a function template palindrome that takes a vector parameter and returns true or false according to whether the vector does or does not read the same forward a backward.` So, for example, a vector with "1,2,3,2,1" would be a palindrome, but a vector containing "1,2,3,4" is not. I accidentially found out that you could do this [on StackOverFlow], template <typename T> bool isPalindrome(const T& theRef) { //solution found on the internet //check to see if theRef's contents is a palindrome return equal(theRef.cbegin(),theRef.cend(),theRef.crbegin()); } but …

Member Avatar
Member Avatar
+0 forum 1

Hi, I am getting below error after executing below code. **Error**: In function `main': undefined reference to `Point2D::Point2D(int, int)' class Point2D { public: Point2D(int,int); int getX(); int getY(); void setX(int); void setY(int); double getScalarValue(); bool operator< (const Point2D &right) const { return x < right.x; } protected: int x; int y; double distFrOrigin; void setDistFrOrigin(); }; int main() { Point2D abc(2,3); set<Point2D> P2D; P2D.insert(abc); // i am getting error here ,i dont know why return 1; }

Member Avatar
Member Avatar
+0 forum 3

Hello , I have map of the following type: typedef map < int, vectorofInts > , Now the map has finite size. Each user when he registers, he will be allocated a key. Lets say the map size is 4. U1 will be allocated in K1. next U2 on K2, U3 on K3, U4 on K4. Later it happens in round robin way, U5 with K1 etc. Meantime, U1 may dropoff, in that case U6, needs to be allocated K1. to keep uniformity. Any feedback or idea regarding this alogrithm and optimum way to implement. Sorry that i am not …

Member Avatar
Member Avatar
+0 forum 4

Hi, In the legacy implementation, there is a Queue (which stored the PDUs) which need to be retransmitted. The queue has been implementated as stl map (c++). So the last element in the Queue may not be the largest SN, as per transmit window. Is there any easy way to derive the largest SN (key) in the map ? thanks, pdk

Member Avatar
Member Avatar
+0 forum 1

How to sort vector<int> v{3,2,7,6,5,8,1,2,3,4,5}; in decreasing order using function object. I did using lambda expression sort(v.begin(),v.end(),[](int a , int b){return a > b;}); But How we do using fn object

Member Avatar
Member Avatar
+0 forum 1

int main() { map<string,size_t> count; string word; while(cin >> word) count[word]++; --------(1) for(auto it=count.begin();it!=count.end();++it) cout << it->first << ": "<< it ->second <<endl; I donot understand the code particularly the line (1) Could anyone can explainÉ

Member Avatar
Member Avatar
+0 forum 4

implement a generic fn mapf with prototype template<class Sequence c , class UnaryFunction) Sequence mapf(Sequence c , UnaryFunction f) for ex if c is a seq containing the seq (3,2,7,6,8) and f is the fn that returns twice it integer agument. then container returned by mafc(c,f) is a list containing the seq(6,4,14,12,8). Any hint/idea to solve it.

Member Avatar
Member Avatar
+0 forum 3

given int a[]= {3,2,7,6,8,1,4,5} vector<int> v(a,a+8) use the stl copy algorithm to display the last 5 integers in the vector to cout with each integer on a seperate line. copy takes three argument. third argument is output container. In this case it is v.but v already have 8 elemenst. How to solve this pb?

Member Avatar
Member Avatar
+0 forum 1

Hi Does anyone know if there is an equivilent of std::stoi (string to Int) for use with wstring that I am missing? Seems a bit odd that it would be ommitted from the library, but I cannot find anything. Thank you for reading.

Member Avatar
Member Avatar
+0 forum 2

Hello! I'm writing some mathematical iterators over some big classes that I don't want to store in memory at all, but I still want to be able to iterate through them. As an example (but I have a few of these), think of a class `Combinations({0,1,2...7}, 3)`, which means I would like to iterate over all subsets of size 3 from the set `{0,1,2...7}` I already have the code for this, that's not my problem. The thing is, I'd like to make it compatible with the STL. Right now, I have only one class, which is called "CombinationsIterator" that has …

Member Avatar
Member Avatar
+1 forum 2

When I try to find all subsets of a set using the following code, the iterator vit in the inner for loop of the getPowerSet function misses out on one element certain times. Can anyone tell me why? #include<iostream> #include<vector> #include<set> using namespace std; vector< set<char> > getPowerSet(const set<char> &given); void printPowerSet(const vector< set<char> > &powerset); void printSet(const set<char> &input); int main() { int mychars[] = {'a','b','c','d'}; set<char> given(mychars, mychars+4); vector< set<char> > powerset = getPowerSet(given); printPowerSet(powerset); } void printSet(const set<char> &input) { set<char>::const_iterator it = input.begin(); for( ; it!= input.end(); ++it) cout << *it << " "; } void …

Member Avatar
Member Avatar
+0 forum 3

I have been having this problem since I started using stl containers awhile ago. Basically, when I debug them with the default Code::Blocks MinGW debugger I find that it gives far too much irrelevant information such as iterators and other 'behind-the-scenes' stuff. I can make it better by telling it to watch it as an array, then t just shows the data. But now I have a vector of vectors of decent sizes, and right clicking each one and telling code::blocks to watch them as an array is just not something that I am going to do. Anybody know how …

Member Avatar
Member Avatar
+0 forum 2

Hi everybody, Please excuse the noob question as I am new to STL in C++. I am trying to write a very basic program which uses iota. However my compiler is complaining that iota does not exist in algorithm. Some other forums suggested including <backward/algo.h> as iota could have been depreciated. However my code still does not compile. Can some one take a look? #include<iostream> #include<vector> #include<algorithm> #include<iterator> #include<backward/algo.h> using namespace std; int main(){ vector<int> myVector; iota(myVector.begin(), myVector.end(),100); copy(myVector.begin(), myVector.end(), ostream_iterator<int>(cout," ")); cout<<endl; } I am using g++ on Ubuntu and my compiler version is 4.4.3

Member Avatar
Member Avatar
+0 forum 3

Hi Folks, Here is another noob question. I am trying to write a simple predicate for the find_if function in STL. Here is my code #include<iostream> #include<vector> #include<algorithm> #include<iterator> using namespace std; class InRange{ const int& low; const int& high; public: InRange(const int& l, const int& h): low(l), high(h){} bool operator() (const int& myValue){return (myValue > low) && (myValue < high);} }; int main(){ vector<int> myVector(8); myVector.push_back(10); myVector.push_back(15); myVector.push_back(20); myVector.push_back(25); myVector.push_back(30); vector<int>::iterator myIterator; copy(myVector.begin(), myVector.end(), ostream_iterator<int> (cout," ")); cout<<endl; myIterator = find(myVector.begin(), myVector.end(), InRange(10,20)); cout<<"Found "<<*myIterator<<endl; cout<<endl; } However I am making some obvious mistake as the code just does …

Member Avatar
Member Avatar
+0 forum 1

Hello everybody, I am trying to teach my stl and after writing some basic programs I have hit a road block. I have an iterator which I am trying to pass to a function template Here is my function template template <class T> void display(typename vector<T>::iterator start, typename vector<T>::iterator end){ cout<<"My display "<<*start<<endl; } Here is the call to this function vector<int>::iterator myBeginIterator; vector<int>::iterator myEndIterator; myBeginIterator = myVector.begin(); myEndIterator = myVector.end(); display(myBeginIterator,myEndIterator); Howevert this code refuses to compile. The compilation error is error: no matching function for call to ‘display(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >&, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >&) I …

Member Avatar
Member Avatar
+0 forum 4

I decided to learn C++ STL and I was exprimenting with STL containers. I saw this example [here](http://www.cplusplus.com/reference/stl/vector/insert/): // inserting into a vector #include <iostream> #include <vector> using namespace std; int main () { vector<int> myvector (3,100); vector<int>::iterator it; it = myvector.begin(); it = myvector.insert ( it , 200 ); myvector.insert (it,2,300); // "it" no longer valid, get a new one: it = myvector.begin(); vector<int> anothervector (2,400); myvector.insert (it+2,anothervector.begin(),anothervector.end()); int myarray [] = { 501,502,503 }; myvector.insert (myvector.begin(), myarray, myarray+3); cout << "myvector contains:"; for (it=myvector.begin(); it<myvector.end(); it++) cout << " " << *it; cout << endl; return 0; } …

Member Avatar
Member Avatar
+0 forum 2

hello there, I'm trying to sort a list according to the "length" paramter in ascending order, which represents the third coloumn. List elements are read from a csv file contains 9 coloumns, I only push 6 coloumns in "futurelist" which is the information i'm intersted in. //input csv data [CODE] 1031 17:11 574.1025391 MB 1050 17:30 19 0 0 1326 22:06 536.0175781 MB 1343 22:23 17 0 0 2721 45:21:00 608.1279297 MB 2741 45:41:00 20 0 0 32 0:32 575.8115234 MB 51 0:51 19 0 0 1161 19:21 652.6259766 MB 1182 19:42 21 0 0[/CODE] contents of the list before …

Member Avatar
+0 forum 0

Hello there, submissiontime length finishtime remainingtime 1031 17:11 574.1025391 MB 1050 17:30 1 1326 22:06 536.0175781 MB 1343 22:23 2 2721 45:21:00 608.1279297 MB 2741 45:41:00 3 32 0:32 575.8115234 MB 51 0:51 4 1161 19:21 652.6259766 MB 1182 19:42 5 937 15:37 288.7597656 MB 946 15:46 6 3087 51:27:00 912.9931641 MB 3117 51:57:00 7 I'm trying to read this Excel (CSV) file and display the elements, I'm only interested in displaying the elements with title above, (1st, 3rd, 5th and 7th coloumns), I managed to do this but, the final line is duplicated and starts by 0 when I …

Member Avatar
Member Avatar
+0 forum 4

I am declaring a structure as this [CODE]typedef struct Request { deque<int> roomsList ; }Request;[/CODE] Then , in some other function I get a segmentation fault in the highlighted line : [CODE] int initRoomsList(Request *R) { int roomSatisfying ; char roomName[20] ; int roomNum, capacity,wb,proj, lcd, sound, aud, vid , ac ; int count = 0; FILE *fp ; fp = fopen("rooms.txt","r") ; while(fscanf(fp,"%d %d %d %d %d %d %d %d %d %s", \ &roomNum,&capacity, &wb,&proj,&lcd,&sound,&aud,&vid,&ac,roomName) != EOF ) { if(R->capacity > capacity ) continue ; if(R->wb > wb ) continue ; if(R->proj > proj) continue ; if(R->lcd > lcd …

Member Avatar
Member Avatar
+0 forum 5

I'm trying to sort an array of numbers in ascending order and don't know whats wrong with my code (I'm completely new to vectors). I should first copy the input array (data) into an STL vector, then apply STL’s sorting algorithm to the vector, and finally copy the vector back into the array. void STLSort(int data[],int size) { vector<int> a1; a1.reserve(size); for(int i=0;i<size;i++) a1[i]=data[i]; sort(a1.begin(),a1.end()); for(int i=0;i<size;i++) data[i]=a1[i]; } Thanks.

Member Avatar
Member Avatar
+0 forum 9

Hello just curious, I know that i'm supposed to use new in c++ but decided to experiemnt with malloc. Can you explain to me why the following code crashes and what is the reason. I was under the impression that the size of vector is fixed as it just stores a pointer to an dyanamic allocated array which holds the elements. [ICODE]#include<iostream> #include<vector> using namespace std; int main() { vector< string > * u = (vector< string >*) malloc( sizeof(vector< string >)) ; *u = vector< string >(10,"test"); system("pause"); }[/ICODE] My understanding is that malloc allocates memory to the size …

Member Avatar
Member Avatar
+0 forum 13

The End.