C++ :: Combine Multiple Vector Containing Binary Data To String?

Mar 16, 2012

Two questions:

1. I have some vector<unsigned char> containing binary data. I would like to combine them into one std::string. How is the correct way to accomplish this?

This is my best guess for sample code:

Code:
vector<unsigned char> data; //conatins some data
vector<unsigned char> data2; //contains more data
string temp(data.begin(), data.end());
temp.append(data2.begin(), data2.end());

Will this code work with binary data, or will it null terminate?

2. A similar problem.. I have some unsigned char* variables, and I want to combine them into one std::string. How can I accomplish this? will the member append() work here? or will it null terminate? Something like:

Code:
unsigned char* data; //conatins some data
unsigned char* data2; //contains more data
string temp(reinterpret_cast<const char*>(data));
temp.append(string(reinterpret_cast<const char*>(data2)));

Will the above sample code work without null termination?

View 4 Replies


ADVERTISEMENT

C++ :: Writing Data On A File In Binary Mode Multiple Times

Oct 20, 2013

When you have to write data on a file in binary mode multiple times (without closing the file), is the put pointer left where you ended writing the last time, or do you have to use tellp() or seekp() again and again to make sure you write at the right place?

I would have the same question about the get pointer, does he stay in place after you're done reading something (without closing the file, of course), or do you have to set it back at the right place with seekg() ??

View 5 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C# :: Combine Query To Show All Data

Sep 22, 2014

So I've been working on this for awhile and FINALLY got it to work. This is my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

[Code] ....

As you can see I will have the Name and total right next to eachother.. Problem is I dont want to make a million MySQLCommands for each ID.. Is there a Way I can list all data in each label?

For instance the Select from Text will show all the text from each different ID
and the Select from STOCK-USED as total will show all the total for each ID

Instead of having to list them individually.

Even if I leave it to this

"Select text FROM `parts`";

It selects the 2nd ID in my database and displays its text.. Forgets about the first one completely ...

View 2 Replies View Related

C++ :: Getting Multiple Ints From String Data

Feb 18, 2013

I'm having trouble making a .obj loader at present I'm trying to load faces that are defined as follows:

f 1/1/1 2/2/2/ 3/3/3

So far I've separated the the three number groupings into three strings, I've had a few issues with stringstreams and would like a simple solution.

View 1 Replies View Related

C++ :: Generate A Binary String Based On Hex Data

Apr 23, 2013

Generate a binary ascii characters(weird character ) based on Hex:54313032202020303030 data in C++

View 3 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 :: Store Data In Binary File Then Use It To Find Inverse Of Matrix Form Of Data

Dec 6, 2013

I need to find inverse of a matrix data in binary file should be used to form matrix.its not finding inverse correctly rest is working good.

Code:
#include <stdio.h>
void createbin();
void display();
void inverse();
int main()
{
createbin();
display();
inverse();

[Code] ....

View 4 Replies View Related

C++ :: Vector - Multiple Bullets Acting As One

Sep 24, 2014

I'm trying to make a 2d shooter with SDL and I got as far as having multiple bullets but they act as one when a bullet goes off screen. I shoot 1st bullet, then I shoot 2nd bullet. 1st bullet goes off screen (deletes) and 2nd bullet disappears. I shoot 3rd bullet, 2nd bullet reappears where it disappeared and repeat.

class Bullet {
public:
static const int BULLET_WIDTH = 15;
static const int BULLET_HEIGHT = 25;
static const int BULLET_VEL = 5;

Bullet();
//xFire, yFire - position relative to player

[Code] ....

I'm guessing the problem is in the bullet_move function, but I just don't know what to do.

View 1 Replies View Related

C++ :: Erase Multiple Values In A Vector

Mar 17, 2014

I wud like to delete multiple values from a vector using indexes as my values r not fixed they may change so using indexes i want to delete

For example: vector<int> v={1,2,3,4,5};

I want to erase 3,4,0 indexes

So resulting vector is 2,3

View 6 Replies View Related

C++ :: Search A Vector Element With Multiple Strings?

Nov 22, 2013

How could I search a vector element with multiple strings

i.e. vector.at(i) = This is a test

How could I search that to look for the word "test" in that element?

View 7 Replies View Related

C++ :: Accessing And Working With Vector From Multiple Threads

Oct 20, 2014

I have a vector that I would like to access and work with from multiple threads. I have created an example below to illustrate the functionality that I would like to accomplish.

The goals are to be (1) high speed, (2) thread safe, and (3) *if possible* continue to use vectors as my larger project uses vectors all over the place and as such I would like to maintain that.

However, if I need to switch from vectors to something else then I am open to that as well.

The following example below compiles but crashes rather quickly because it is not thread safe.

How I can fix the example below which I can then apply to my larger project?

#include <string>
#include <vector>
#include <ctime>
#include <thread>
#include <iostream>
#include <random>
#include <atomic>
#include <algorithm>
enum EmployeeType {

[Code] ....

View 1 Replies View Related

C :: Binary File Write By User Input Then Printing Binary File Data Out

Dec 6, 2013

Following is the program I wrote it basically takes 9 inputs and then save them into binary file. then print out the data stored in binary data and find inverse of it then print the inverse out. but its stuck in a loop somewhere.

Code:
#include <stdio.h>
int main() {
int a[3][3],i,j;
float determinant=0;
int x;
FILE *fp = fopen ("file.bin", "wb");

[Code] .....

View 6 Replies View Related

C++ :: Reading A Binary File Into A Vector

Jan 26, 2014

My program writes a vector to a file in binary. I want to erase the vector, then read the file to repopulate the vector then display.

Basically I want to erase the RAM memory and be able to use the file as memory. This is my current code but it is not reading the file correctly. I have checked the file to see that the writing part is working.

void read_from_file(vector<Info> &vector)
{fstream file;
file.open("info.dat", ios::binary | ios::in);
if (file.fail())
{
cout<<" FILE DOES NOT EXIST ";
system("pause");

[Code]...

View 7 Replies View Related

C++ :: Combine RGB (A) Pixels Into One?

Jan 14, 2013

I have a buffer which has a virtual width of 1024 pixels with virtual height 768 pixels (actual width stored in GPU.GPU_screenxsize, height in GPU.GPU_screenysize (both uint_32)).

I currently use the following function to plot the pixels to the screen:

inline void GPU_defaultRenderer() //Default renderer {
uint_32 pixel;
int bufferx; //Buffer's x!
int buffery; //Buffer's y!
int bufferxstart; //Buffer's x start!
int bufferystart; //Buffer's y start!
int pspx;

[Code] ...

How to combine the pixels together (blend them into one goal pixel) to get a better view? (Currently it takes the bottom right pixel of the area that represents the goal pixel).

So (x1,y1,x2,y2)->(pspx,pspy) = (bufferystart,bufferxstart,buffery,bufferx)->(pspx,pspy).
Atm this is (x2,y2)->(pspx,pspy)

Btw the pixel format is uint_32 RGBA (only RGB used atm). The psp_graphics_putpixel draws it onto the real VRAM. PSP_SCREEN_ROWS and PSP_SCREEN_COLUMNS represent the destination screen (the real screen)'s height and width in pixels.

View 7 Replies View Related

C++ :: Combine Two Program Into One?

Jan 13, 2015

i tried to combine two programs into one.. in my first program it has one class object and main() and my second program it has only one main()

i want to combine these two into one

View 5 Replies View Related

C# :: How To Combine Two SQL Queries Into One

May 21, 2014

update Tag_Master set flag='Inactive' where Tag_no=10;

update Tag_Master set flag='Assigned' where Tag_no=12;

I had these two queries, I just want both of these will fire on same event. Is any other way to write both queries in single query instead of writing two different queries ....

View 4 Replies View Related

C :: Compare String User Input With A String In Binary

Jul 14, 2014

I have problem with string compare. I want to compare the string user input with a string in binary. And I don't know how to do it. Problem in function login();Here is the code: And you also can download file in attachment too..

Code:

#include<conio.h>#include<dos.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
char nsb=1;
char ch, password[20], passlogin[20], inputpass[20], checked[20];
FILE *fp;
}

[code]....

View 1 Replies View Related

C :: Binary Tree - Return A Vector Of Integers

Oct 19, 2014

So I have a Binary Tree and I need to return a vector of integers (the nodes) of the heaviest path in the tree.

First, is it possible to do in C? Because I think a vector is an ADT in C++.

I've started writing something recursive, which worked for a balanced tree of height 1, and failed for longer height.

This is what I've written - [URL] ....

View 6 Replies View Related

C++ :: Vector Of The Highest Path In Binary Tree

Oct 21, 2014

I have a function signature: vector<int> tree_highest_path (Node *root);

Which gets a pointer to a binary-tree root.(the struct is:[int id, Node *right, Node left].

I need to return a vector of id's of the highest path of the tree.

Example: root:6, left of root:5, right of root:3, right of right:1

will return this vector: 6->3->1.

View 3 Replies View Related

Visual C++ :: How To Do Binary Search On A Vector Of Strings

Sep 25, 2012

I'm trying to do a binary search on a vector of strings and keep getting this error. This is the PhoneEntry header file with the class declaration:

Code:
using namespace std;
#include<string>
#include<iostream>
#include<fstream>
#include<vector>
#include"phoneNumber.h"

[Code] .....

View 5 Replies View Related

C++ :: Multiple Quiz Program - Adding High Score For Each User Stored In Binary File

Jul 11, 2014

I am making a multiple quiz program. So everything is working fine, except for the part where i'm trying to add a highscore for each user which is being stored in a binary file. I have added a sample of the program containing the error. This isn't the actual program, which is very long.

class user { //The collection of all info pertaining to the users
char user_id[50];
public:
int hscore1;
user() {
strcpy(user_id,"NULL");
hscore=0;

[Code] ....

View 1 Replies View Related

C++ :: How To Combine Inputs Using If Statements

Jul 19, 2013

How to combine the if statements?

cout<<"Enter a sale number"<<endl;
cin>>rec.sale;
if(cin.fail())
{
cout<<"Enter a number"<<endl;
cin>>rec.sale;
}

[Code]...

View 13 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++ :: Overloading Binary And Assignment Operators In Vector Class

Feb 5, 2013

I am making a vector class and am having some problems creating the overloaded arithmetic operators and assignment operators.

Here is an example of my "+=" code as it stands the errors are similar/the same for the other operators except "=" operator which works fine:

Vector3& Vector3::operator+=(const Vector3 &rhs) {
Vector3 tmp = *this;
Set(tmp.getX() + rhs.getX(), tmp.getY() + rhs.getY(), tmp.getZ() + rhs.getZ());
return *this;
}

I have tried a lot of different approaches ad always get the error:

error: passing 'const Vector3' as 'this' argument of 'double Vector3::getX()' discards qualifiers
error: passing 'const Vector3' as 'this' argument of 'double Vector3::getY()' discards qualifiers
error: passing 'const Vector3' as 'this' argument of 'double Vector3::getZ()' discards qualifiers

View 5 Replies View Related

C++ ::  how To Combine A Function Call And Inputting A Value

Mar 15, 2014

We're working on classes in my programming class, and I have a question about function calls.

Bascially, I have all my set and get functions set up and ready to go.

I was wondering if it was possible to have the user input a variable while calling a function.

for example

cin >> getname();

the user inputs a value that gets passed into getname.

Or does it have to be something like

cin >> name;
getname(name);

mind you all, this isn't code from my program i'm just spitballing here.

View 4 Replies View Related







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