Code: // string::erase #include <iostream> #include <string> int main () { std::string str ("This is an example sentence."); std::cout << str << ' '; str.erase (10,8); std::cout << str << ' ';
Code:
Output:
I don't understand this program. What do these 2 numbers represent? The index of an element in a character array? The 10th character of the array is 'n' and 8th is a "space".
I'm having a problem converting part of a string to an integer.I used strtok to seperate my string and I have also a function for atoi but how to apply it to my strtok function.What i need is to change the char *years to an int.Have a look of what I got:
Code: int main() { char sentence[]="trade_#_2009_#_invest_#_DEALING"; char *word=strtok(sentence, "_#_"); char *year=strtok(NULL, "_#_");; // assigning NULL for previousely where it left off char *definition=strtok(NULL,"_#_"); char *synonyms=strtok(NULL,"_#_");
I have a string that contains a various number of lines which are each separated by and so what I want to do is to put each line into a node in a linked list.The relevant sections in my code are as follows:
Code:
typedef struct line *Line; struct line { char *text; int lineNum; Line next; }
[code]....
Code:
strncpy(curr->text, text[prevPos], subLength);
With this line, I was hoping to make curr->text a string that is length subLength and begins at position prevPos in the text string. Except text[prevPos] is treated as a single character and not a string that begins at that position.
And I want to create a function to print either c or x. However, I don't want to just use a switch or something to figure this out, I want to reference which part I'm outputting.
Now here's the twist
vector<data> dataList;
I need to access element x or c in the vector, but all I pass is the vector and which element, so that I might have something like:
How can I Passe some part of multi-Dimensional Array to a Function; for example only two dimension of three dimension of a an array with 3 dimension. This is because my function is defined for working with 2 dimension arrays.
What is the efficiency of the two assignments (line 1 and 2), i.e. (function calls, number of copies made, etc), also the Big O notation. I know there are function calls for retrieving the size of each string in order to produce a new buffer for the concatenated string...any difference between line 1 and 2 in terms of efficiency?
String s("Hello"); String t("There"); 1. s = s + t; 2. s += t;
int count = t1; while(count>counter){ Sleep(delay); Int32::TryParse(textBox2->Text,add); result = result + add; counter = counter + 1;
Problem is that sleep stops all program for specified time, Is there an alternative to sleep that would only stop part of code or can i use sleep different way to specify what it pauses?
Is there any way I can clear only a selected part of the screen? (I'm aware of system("cls"))
For example, when you enter a date, and is wrong, could it just errase that input and only say "Wrong try again" without errasing everything else you where doing?
In this case, a function that only errases what is in the while
I am having a little bit of trouble with what should be a simple part in my code. For some reason it keeps looping the name part of the program and I seem to be passing over the problem in the code.
Here is the code:
#include <iostream> #include <string> using namespace std;
I made a simple little program that takes text from the clipboard, and spits out all the lines I've copied one at a time (so my program can analyze it).
everything works perfectly, except, it spits it own in the wrong order, I want it to spit out from bottom to top. but currently it spits out the data from top to bottom. here is my code :
Code: #include <iostream> #include <Windows.h> #include <string> #include <sstream> using namespace std; int main() { HANDLE clip; // assigns the var. clip to hold a handle ID.
[Code] .....
I want this loop to run backwards! Like it say's what I want to work backwards. Where as I know how to flip a while loop like this: while(x < 5), how to flip a loop like the one I'm using. how I can do this?
I have a character array that includes configuration bits that are 0x00, thus when I try and do a strcat it adds the appended string into one of those spots instead of the end of the array.
I'm writting an algorithm which equals to std::to_string. The inttostring part is fine, and the decimal_part too. But when the number digits > 5, the program loops infinitely.
I have a vector of sets, which I am removing any element which contains a certain value. For example, if I was looking for 2:
[0] 1 2 3 [1] 4 5 6
After the program was run, I would be left with just [0]4 5 6.
This is the code I have been using
auto iter = std::remove_if( clauseVector.begin(), clauseVector.end(),[propagator] ( const std::set<int>& i ){ return i.find(propagator) != i.end() ; } ) ; clauseVector.erase( iter, clauseVector.end() ) ;
I want to know, is there any way I can tweak this code so that it only removes one part of the set rather than the whole thing. For example with above example, I would be left with
The exercise is : Define a class Arc, which draws a part of an ellipse.
Hint: fl_arc()
And the body of the class ellipse is as follows in the book (PPP):
struct Ellipse :Shape { Ellipse(Point p, int w, int h); //center, max and min distance from center void draw_lines()const; Point center()const; Point focus1()const; Point focus2()const;
[Code] ....
And the fl_arc() probably is part of FLTK which I've installed it on my machine.
Now the problem here is that while I don't can see the full version of the body of the ellipse how to do this exercise?
I'm new to strings. I want to know how to insert a string right in the middle of another string.Is it possible to do that? for example my first random word is 12345678 and the 2nd random word is jimmy I would have to write .
This in my code uno.insert(4,dos); for jimmy to be printed in the middle of the first string,but what if my 1st random word is has more than 8 characters what would I do in that case?
I am using Visual Studio 2008. I just wonder if there are any library function in Windows SDK or MFC, or from third-parties, that can convert a UTF-8 string into Windows Unicode string(used in CString object).
Can MultiByteToWideChar or ATL String conversion macro like A2W to the conversion?
I want to compare the part of the character array with the scanned input. I've initialized the character array (colourCompare).
What I want to do is, if the input colour matches up with one of the elements in the colourCompare array, it will then read the next value(I did not include "read the next value part"). If the input does not match up, then it goes back to the scanning part.
How to find the biggest column of the matrix (higher of main diagonal) Here is the draft of code that i desighned/ Of cause it has a several mistake. My task is here to create the matrix, allocate the dynamic memory for it, and to find the biggest sum of the column elements that is located over main diagonal. So main points is correct memory allocation, and the sorting to the biggest sum of column higher than diagonal.
#include<iostream> #include<conio.h> #include<time.h> using namespace std;
I am supposed to make a program that take a list of integers from the user and to delete the smallest part of it in order to make it sorted in non decreasing order ..
So, I have spent the last week looking googling and researching how to get a standalone copy of the regex part of the boost library to work in a project. This project will be compiled on other machines and I CANNOT have the user install it.
Is there any way to do this?
So far, I have built the regex part: I have both .so files and .a files built. The thing that I'm unsure of is that these were built with gcc and I am using/will be using g++.
I have also finally got the bcp tool to work, and extracted the regex part and all of its dependencies.
I can't get it to compile any way I try to work it. I need this to be in a folder "regex/" folder in my directory.
I have used too many commands to paste them all, but the last I tried was this:
I have also tried many variations of the above command. Such as using -lboost_regex and lots of other things. Is my whole problem because I'm using an .so built by GCC?
The output of the above command was
/usr/lib/gcc/i686-linux-gnu/4.6.1/libstdc++.a(eh_alloc.o): In function `__cxa_allocate_exception': (.text.__cxa_allocate_exception+0xb4): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i686-linux-gnu/4.6.1/libstdc++.a(eh_alloc.o): In function `__cxa_allocate_exception': (.text.__cxa_allocate_exception+0x111): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/i686-linux-gnu/4.6.1/libstdc++.a(eh_alloc.o): In function `__cxa_free_exception':