C++ :: String To Multidimensional Char Vector

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


ADVERTISEMENT

C++ :: Error With Multidimensional Vector

Jun 22, 2013

I am having trouble accessing a one-dimensional vector as a multi-dimensional one.I have a MultiArray template class, and it is accessed using the function operator. It accesses elements through the expression row * m_columns + col. The row and col are the two inputs to the operator while the m_columns is the width/number of columns in the array. There is also a version that accesses the array with one number. Its underlying representation is a one-dimensional vector.The problem is when I try to load a level:

void Map::LoadFromFile(const std::string& filename) {
std::ifstream map_file(filename);
std::cout << m_map.GetHeight() << ", " << m_map.GetWidth() << std::endl;
std::cout << m_map_dimensions.y << ", " << m_map_dimensions.x << std::endl;
if(map_file.is_open())

[code].....

View 4 Replies View Related

C++ :: Parsing Multidimensional Vector Into Array

Nov 30, 2013

For a rather complex and strange reason that I won't explain right now, I need to have this going on in my program.

class FVF{
private:
vector<vector<float>> data; //Contains fvf data for Direct3D stuff
public:

[Code].....

The FVF allows this Model3D class to also be compatible with file handling methods I've got, but here's the problem. D3D buffers require an array to feed them the information, and I know that for a single dimension of vector I can use vec.data(), how to do this for multiple dimensions.

I think the best Idea I've got so far is to set the vector within the Model3D class as a pointer, then I can union it with a float pointer... Once I can guarantee the information is correct and complete, manually transfer the contents of the vectors into the float pointer.. (The union is to reduce memory needed instead of having the data repeated in vectors and arrays)

how I could just pass these as arrays?

View 4 Replies View Related

C++ :: Read Text File Char By Char By Using Vector Class

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

C++ :: Initializing Multidimensional String Array?

Nov 15, 2014

In one of my programs I have a 3x3 array of string that I use to display the outcome to rock, paper, scissors, and another 1x3 used for a number guessing game. I have the arrays declared in the header file as follows:

//Games.h
std::string rpsOutcome[3][3];
std::string hiLoOutcome[3];

and then initialized them in the cpp file:

//Games.cpp
string rpsOutcome[3][3] {
//row 1
{ "Both of you picked rock, you tied. Try again",
"You picked rock, the computer picked paper, you lose",

[code]....

From what I've read, Im pretty sure thats how your supposed to initialize multidimensional arrays (using the nested braces), but when I build the project, I get the following error:

123456789101112
1
1> RockPaperScissors.cpp
1> Games.cpp
1>c:userswuubbgoogle drivevisual studio projectsgamesgamesgames.cpp(75): error C2374: 'games::rpsOutcome' : redefinition; multiple initialization

[Code] .....

View 4 Replies View Related

C++ :: Open File And Read In Rows To String Vector And Return Vector

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

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 View Related

C++ :: How To Make Vector Of Char

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

C++ :: Transform TXT File To Char Vector?

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

C/C++ :: Sending Char And Storing It In Vector

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

C++ :: Print Linked List But As A Vector Of Char

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

C++ :: Deleting Vector With Char - Segment Fault

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

C++ :: Char Vector - Fixed Size Two Dimension Array

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

C++ :: Count String In A String Using Datatype Char

Dec 20, 2014

I have the codes for such a problem where, to create a program that counts how many times the second string appears on the first string. Yes it counts if you put 1 letter only, but if you put 2, it is an error. As an example. If the first string is Harry Partear, and the second string is ar, it must count as 3. Here's the code:

Code:

#include <iostream>
#include <conio.h>
using namespace std;
int main ()

[Code] ....

View 6 Replies View Related

C++ :: Char Array To String - String Becomes Garbage

Apr 20, 2013

I'm trying to "tokenize" a string using std::string functions, but I stored the text in a char array. When I try to convert it to a string, the string has the first character right but the rest is garbage.

// Get value from ListBox.
char selectedValue[256];
memset(selectedValue, NULL, 256);
SendMessage(GetDlgItem(hWnd, IDC_LB_CURRENTSCRIPT), LB_GETTEXT, selectedIndex, (LPARAM)selectedValue);
// Convert to string.
string val(selectedValue);

[Code] ....

View 3 Replies View Related

C++ :: String Class That Finds A Char In String?

Feb 5, 2013

A string class that finds a char in the string?

View 1 Replies View Related

C/C++ :: Comparing Input String To Type String Vector

May 29, 2014

I wrote a program that reads a list from a file and stores it in a string type vector. Now, I want the user to input a word so that the program can search the vector to see if that word already exists. I have used every possible way of reading input from the console and storing it in order to compare with the vector but it never results in a match. When I print the input string and the vector string they are exactly the same thing (or at least print to the console as if they were). I've tried using getline; using cin direct to a string var; using cin to a char array and then casting to string using string str(arr); I even added a newline at the end just in case and STILL I cannot get a match.

vector <string> currentSet; //read a list in from a file and has 9 items in it
cin.ignore();
string line;
getline(cin, line);
if(line == vector[0]){//if printed to console line is HEAT and vector[0] is HEAT
cout<<"match"<<endl;
}

View 3 Replies View Related

C++ :: Getting A Char From A String

Apr 5, 2013

I have this problem that I don't know how to sort out. I have a feeling it's really simple

#include <iostream>
#include <string>
void main () {
char test[10] = "gorilla";
char try = test[1];
cout << try;
}

I get the error:
lab4.cpp:6: error: expected primary-expression before "char"
lab4.cpp:6: error: expected `;' before "char""

View 2 Replies View Related

C :: How To Get ASCII Value Of A Char In A String

Mar 4, 2013

how can I find ASCII value (0..255) of a character char in a string?

I have an array of char:

Code: char myarray[50]; and I need to have ASCII value of character eg myarray[10]. How can I do that?

View 1 Replies View Related

C++ :: Char Array To String

Oct 19, 2013

I have some code:

char cHomeTeamFaceOffsPercentageWon[100];
memcpy(cHomeTeamFaceOffsPercentageWon,cSqlHomeTeamFaceOffsPercentageWon,100);

After this, for example, cHomeTeamFaceOffsPercentageWon is, "29%".

Then, I use

std::string szwPercentageWon = std::string(cHomeTeamFaceOffsPercentageWon);

szwPercentageWon is then, "2". Shouldn't this convert correctly, to "29%" as well.

Or is there something I'm missing? Maybe the termination character, or something.

View 1 Replies View Related

C++ :: Convert String To Char

Apr 30, 2013

Is there anyway to convert std::string to char*?

Like:

std::string x="hello world";
char* y=x;

View 6 Replies View Related

C++ :: How To Transform A String Into A Char

Feb 8, 2015

I have had quite a head spinner on trying to transform a string into a char. I've been trying to do this for the project below.

[URL] ....

std::string str = "string";
const char* chr = str.c_str();
cout << *chr << endl;

Above is the code I have tried using and it stores data under *chr, it however only stores one letter rather than the entire word like for example string.

View 2 Replies View Related

C++ :: Convert String Of Hex To Char

Jul 5, 2013

I have this code working:

char tmp_wku[3];
tmp_wku[0]=0x01;
tmp_wku[1]=0x9D;
tmp_wku[2]=0x62;
char tmp_com[11];

[Code] ....

This sends the buffer to a LIN modem. My question is: can this be done better. If I have a astring of hex numbers like "09 98 88 55 42 FF 00 00 FF BD 89". How could I send this without manually makng a char with hex numbers?

View 1 Replies View Related

C++ :: Replace Char In String

May 7, 2013

Is there a way to replace 3 char's in a string. For example i have a string containing

s = "The school is called 7x8"

I want to replace the "7x8" with "LSU". But the "x" can be any letter or number.

Is there a way to do that ?

View 6 Replies View Related

C++ :: Remove Char From String?

Aug 9, 2013

I've to do a function that removes char(input by user) from string , only if it appeared and to reduce spaces.

for instance: string = abcabcd ; and the char= c/
the return string is : ababd

void removeChar(char string2[SIZE], char ch) {
//---NOTE--- its not completely works - there is a problem i.
int read = 0, write = 0;

[Code].....

View 6 Replies View Related

C++ :: Conversion Between Char And String

Jun 7, 2013

I have a question on conversion between char & string. I have cut & pasted the part of the code from my C++ code and my function "decryptPwd" uses C style code with "char" etc.

I need to pass a string (mypwd) somehow to this function after conversion & then compare it to another string (newmypwd).

I tried - "decryptPwd(mypwd.c_str())==newmypwd.c_str()" but it did not work.

..
#include <string>
..
char* decryptPwd(char hash[64]);
main () {
string mypwd;
string newmypwd;
if (decryptPwd(mypwd)==newmypwd)

[Code] ...

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved