string concat
-
Hi, I understand we can concat strings using + operator. for example,
string strarray[20]; string rule= "1 "; string word = "; hello world"; for(int i=0;i<10;i++){ strarray[i] = rule + word;
} however if i do this, it prompt an error:string strarray[20]; for(int i=0;i<10;i++){ strarray[i] = "Rule " + "; hello world"; }
how do i go about doing this? tks -
Hi, I understand we can concat strings using + operator. for example,
string strarray[20]; string rule= "1 "; string word = "; hello world"; for(int i=0;i<10;i++){ strarray[i] = rule + word;
} however if i do this, it prompt an error:string strarray[20]; for(int i=0;i<10;i++){ strarray[i] = "Rule " + "; hello world"; }
how do i go about doing this? tks -
Hi, I understand we can concat strings using + operator. for example,
string strarray[20]; string rule= "1 "; string word = "; hello world"; for(int i=0;i<10;i++){ strarray[i] = rule + word;
} however if i do this, it prompt an error:string strarray[20]; for(int i=0;i<10;i++){ strarray[i] = "Rule " + "; hello world"; }
how do i go about doing this? tksnuttynibbles wrote:
strarray[i] = "Rule " + "; hello world";
Because in that case you try to concatenate char arrays, not std::string. Thus, there's no + operator overloading for char arrays. The + operator is overloaded by the string object, so it means the left operand of the + has to be a string, not a char array.
Cédric Moonen Software developer
Charting control [v2.0] OpenGL game tutorial in C++ -
Either #1 or 2 below should work... You get an error since you the + operator is not defined between two char arrays 1) strarray[i] = std::string("Rule ") + std::string("; hello world"); 2) strarray[i] = "Rule "; strarray[i].append("; hello world");
WOW im very please with the SUPER quick reponse from both of you. TK you so much. im gonna go with the 2nd solution tho :) however, tks to both again!!!!
-
Hi, I understand we can concat strings using + operator. for example,
string strarray[20]; string rule= "1 "; string word = "; hello world"; for(int i=0;i<10;i++){ strarray[i] = rule + word;
} however if i do this, it prompt an error:string strarray[20]; for(int i=0;i<10;i++){ strarray[i] = "Rule " + "; hello world"; }
how do i go about doing this? tksbtw, is there a function in c++ to search for duplicate items in an array without doing a for loop?
-
btw, is there a function in c++ to search for duplicate items in an array without doing a for loop?