C++ :: How To Concatenate Two Vector Char
Dec 1, 2013
This seamed as a simple thing but i am getting something i did not expect: Example:
Code:
vector<char> StrJoin(SubjSeq.size()+ QuerySeq.size());
cout << StrJoin.size()<<"
"; // size x
StrJoin.insert( StrJoin.begin(), QuerySeq.begin(), QuerySeq.end() );
StrJoin.insert( StrJoin.begin(), SubjSeq.begin(), SubjSeq.end() );
cout << StrJoin.size()<<"
"; // x*2
All structures are vector<char>. when i do the above my characters form Query and Subject are copied in my new vector called StrJoin but the size of that vector is twice the size then it should be.
View 3 Replies
ADVERTISEMENT
Sep 29, 2014
I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.
/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit
[Code]....
View 2 Replies
View Related
Oct 29, 2014
Code:
cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())
[Code] .....
View 8 Replies
View Related
Jun 8, 2013
let say
char temp[8][8];
and you want to make vector of this char
vector<????> boardVec;
View 2 Replies
View Related
Aug 17, 2013
I need to transform a .txt file to a char vector, but how to do it. as much as I could until now been transformed into vector string.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
[Code].....
View 7 Replies
View Related
Feb 3, 2013
I was working on a program which compares sequences of characters, counts the differences between them, and displays them. I had the sequence inputted as a string (into a vector so any number of sequences could be chosen), and then, the way I tried to check the strings for differences, was by converting the string to a (multidimensional) vector of chars:
vector< vector<char> > sequencesC;
for (int a = 0; a < sequenceCount; a++) {
cout << "
Enter sequence " << a+1 <<" name: ";
cin >> sequenceNames[a];
cout << "
[code]....
However, it crashes (as shown above) when I try to set, by a for loop, every char of a multidimensional vector (sequencesC) to the same char of the data vector. Is there any way I can convert the string to a char vector?
View 7 Replies
View Related
Feb 3, 2014
I've got something I'm trying to accomplish, but crashes my program.
I've got my server and client code.
Having the client send a message they type (char Chat[1024]) And the server receiving the chat (char recv_chat[1024]) only to send it to all connected clients again. Which the server sends the recv_chat.
The client receives it (char recv_chat[1024]). This works, and the client gets the right info. However, I'm trying to store it using a vector. I'm sure I've tried any way possible.
Client storing vector pseudo-code:
vector<char*> SaveChat;
int main () {
while (true) {
if (newClientConnected) {
[Code]....
This doesn't work, and crashes my application. I've tried changing the vector to string, const char*, basically anything I can with no avail.
View 8 Replies
View Related
Aug 26, 2013
I was assigned to print a linked list but as a vector of char (I cannot use the normal string type) , this is what I have:
char* List::asString(){
Node* ite = new Node();
ite= first;//ite is like an iterator of the list
for(int i=0; i<sizeOfList; ++i){//sizeOfList is the total of node of the list
[Code] ....
But when I print that, I get a bunch of weird symbols...
View 7 Replies
View Related
Apr 19, 2012
The below code is giving me segment fault during delete [] (*iter) sometimes. Is it not the proper way to delete the vector with char *
Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<char*> nameList;
for (int i=0;i<1000;++i)
[Code] ....
View 7 Replies
View Related
Jun 9, 2013
I want to save the char[8][8] // fixed size 2 dimension array
to a vector
such as
vector<?????> temp;
is there anyway to approach this?
View 4 Replies
View Related
Mar 17, 2014
I want to concatenate string+int so i make like that
Code:
for(int i=0;i<n;i++)
{
name="obstacle"+i;
cout<<name;
}
I get in the window
obstacle
obstacl
obstac
obsta
obst
...
..
o
but i want instruction that allow me to get
obstacle0
obstacle1
obstacle2
...
View 6 Replies
View Related
Oct 19, 2013
Trying to concatenate the 1st and 2nd element from an array of chars. Then this to be used as a hex value.
so for example
specs[0]='f'
specs[1]='4'
concatenate_value=0xf4
View 9 Replies
View Related
Oct 15, 2014
How i can concatenate two integers into one integer. I have code that concatenate two integers but if the 2nd integer is zero it won't work. How can i modify it so that it can cater the case of y=0 too.
Code:
int concatenate(int x, int y) {
int pow = 10;
while(y >= pow)
pow *= 10;
return x * pow + y;
}
View 12 Replies
View Related
Nov 15, 2014
when i was finding a way to concatenate three integers in C, I came across a snippet like this
Code:
#include<stdio.h>
#define cat(a,b,c) a##b##c
int main()
{
int d;
d=cat(1,2,3);
return 0;
}
How the macro works here? I am unable to understand the function '#' plays in the macro.
View 1 Replies
View Related
Apr 19, 2013
I m concatenating specific range of digits that are same from an array "element" . I have problem with range. As in my case the range is col_elem[ii]=4, but it will continue reading the next element if it is the same. My code is:
Code:
int element[8]={0,1,3,3,3,0,1,2};
col_elem[ii]=4;
for (rr=0; rr<col_elem[ii];rr++){
join_tmp[qq]=rr;
while ((element[ii]== element[ii+1]) ) {
[code]....
View 4 Replies
View Related
Mar 6, 2014
The objective of the project is to become familiar with linked lists by writing a series of basic functions that allow us to manipulate a set of linked lists. I've completed all of the functions except for one.
The function I am stuck on is supposed to do the following:
concatenates list1 and list2 to form a new list,
and returns a pointer to this new list;
Note: new list contains copies of all nodes in list1 and list2 */
View 7 Replies
View Related
Sep 6, 2013
I have a function that concatenate the strings in an array(2D)
Ex 1: Sean Connery Micheal King James Wood
Result: SeanConnery MichealKing JamesWood ...
The concatenation function working correctly and displays correctly in the function. But if I make another function to display it, it shows this
Ex 2: SeanConnery Sean MichealKing Micheal JamesWood James..
It adds to first name. Why?
Code:
void Concatenation( char dest[200][13] ) {
// loop through and concatenation the strings
for(int i=0;i<200;i+=2) {
myStrCat(dest[i],dest[i+1]); // mystrcat is equalto strcat()
[Code] .....
View 4 Replies
View Related
Apr 22, 2013
Actually i found some mistakes in my post. So here is the modified version. I want to concatenate the indexes of elements of array that has the same value for specific range.In my case the range is 4
Code:
int element[8]={2,2,0,3,3,0,1,2};
col=4;
int rr;
int qq=0;
for (rr=0; rr<col;rr++){
join_tmp[qq]=rr;
while ((element[rr]== element[rr+1]) ) {
join_tmp[qq]= concatenate(rr+1, join_tmp[qq]);
printf("%d
",join_tmp[qq]);
rr++;
}
qq++;
}
Code:
//FUNCTION TO CONCATENATE INTEGER VALUES OF SAME GROUP IN A COLUMN
unsigned concatenate(unsigned x, unsigned y) {
unsigned pow = 10;
while(y >= pow)
pow *= 10;
return x * pow + y;
}
Code: I want input like
10
2
3
Instead i get
10
2
34
how can i fix it so it will only iterate to the specific range?
View 2 Replies
View Related
Mar 30, 2015
I have two std::string data items that contain binary data (so it may have the null character!). What is the proper way to concatenate them to preserve all of the data? I am guess a simple:
string string3 = string1 + string2;
Will not work, as it will terminate string3 on the first NULL character it encounters.
View 3 Replies
View Related
Jul 31, 2013
How can I concatenate two 2-dimensional int arrays into one larger 3-dimensional array. This question is also valid for the 3-dimensional vectors. I know the command for the one dimensional vector as:
std::vector<int> results;
results.reserve(arr1.size() + arr2.size());
results.insert(results.end(), arr1.begin(), arr1.end());
results.insert(results.end(), arr2.begin(), arr2.end());
and for the one dimensional array as:
int * result = new int[size1 + size2];
copy(arr1, arr1 + size1, result);
copy(arr2, arr2 + size2, result + size1);
But I do not know how to make a 3-dimensional array or vector.
View 3 Replies
View Related
Dec 23, 2014
I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.
this is the entire code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
[Code]....
at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.
View 4 Replies
View Related
Nov 28, 2013
I need to do a function that copy every word from a text to a char word. How can i do it?
View 5 Replies
View Related
Feb 9, 2015
How to output vector contents using the push_back function. My program reads in values just fine, but it does not output anything and I've been stuck on why.
here is my code:
#include <iostream>
#include <array>
#include <vector>
using namespace std;
int duplicate( vector < int > &vector1, const int value, const int counter)
[Code].....
View 3 Replies
View Related
Jun 7, 2012
I have a cpp app that reads in a number of files and writes revised output. The app doesn't seem to be able to open a file with a ' in the file name, such as,
N,N'-dimethylethylenediamine.mol
This is the function that opens the file :
Code:
// opens mol file, reads in rows to string vector and returns vector
vector<string> get_mol_file(string& filePath) {
vector<string> mol_file;
string new_mol_line;
// create an input stream and open the mol file
ifstream read_mol_input;
read_mol_input.open( filePath.c_str() );
[Code] ....
The path to the file is passed as a cpp string and the c version is used to open the file. Do I need to handle this as a special case? It is possible that there could be " as well, parenthesis, etc.
View 9 Replies
View Related
May 13, 2013
I need to create a class vector as a template and define operations on vectors.
And this is what I made.
#include<iostream>
using namespace std;
template<class T>
[Code].....
View 2 Replies
View Related
Mar 26, 2013
Lets say that I have a vector of vector of integers. <1,2,3,4> , <5,6,7,8>, <10,11,12,13>
How do I make a function that creates vector of vector of every different integers?
<1,5,10> , <1,5,11>, <1,5,12>, <1,5,13>
<1,6,10> , <1,6,11>, <1,6,12>, <1,6,13>
<1,7,10> , <1,7,11>, <1,7,12>, <1,7,13>
<1,8,10>, <1,8,11>, <1,8,12>, <1,8, 13>
<2,5,10>, <2,5,11>, <2,5,12>, <2,5,13>
and so on...
View 2 Replies
View Related