Hi group,
how to convert a string to a vector of unsigned char ?
I used to iterate trough the string to set the vector, but I think
this is not the best way to do this.
I'm a beginner with the STL
How about allocating the vector ? should I know before the size ?
And I would like to do then opposite conversion, from an unsigned char
vector to a string.
How to do this ? how about special caracters ? (\n for example)
Thanks for your help
Best regards,
N. 3 40659
* ti*********@gma il.com:
>
how to convert a string to a vector of unsigned char ?
std::string s = "abra kadabra";
std::vector<uns igned charv( s.begin(), s.end() );
I used to iterate trough the string to set the vector, but I think
this is not the best way to do this.
I'm a beginner with the STL
How about allocating the vector ? should I know before the size ?
Huh.
And I would like to do then opposite conversion, from an unsigned char
vector to a string.
How to do this ?
std::string t( v.begin(), v.end() );
how about special caracters ? (\n for example)
Irrelevant.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
On 2 Apr, 14:20, timor.su...@gma il.com wrote:
Hi group,
how to convert a string to a vector of unsigned char ?
I used to iterate trough the string to set the vector, but I think
this is not the best way to do this.
I'm a beginner with the STL
How about allocating the vector ? should I know before the size ?
If you have very large strings you can run v.reserve(s.siz e()) before
inserting, which might give a speed improvement. But you don't have
to.
--
Erik Wikström
On 2 avr, 15:37, "Erik Wikström" <eri...@student .chalmers.sewro te:
On 2 Apr, 14:20, timor.su...@gma il.com wrote:
Hi group,
how to convert a string to a vector of unsigned char ?
I used to iterate trough the string to set the vector, but I think
this is not the best way to do this.
I'm a beginner with the STL
How about allocating the vector ? should I know before the size ?
If you have very large strings you can run v.reserve(s.siz e()) before
inserting, which might give a speed improvement. But you don't have
to.
--
Erik Wikström
Thanks both for your answer, that solves my problem :)
Best regards,
N. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Joseph Turian |
last post by:
Some function requires a vector<const foo*> argument.
How can I cast a vector<foo*> to vector<const foo*>?
Thanks!
Joseph
|
by: sshock |
last post by:
Hi all,
I want to read from a file into a vector<unsigned char>. Right now my
code looks like this:
FILE* f = fopen( "datafile", "rb" );
enum { SIZE = 100 };
vector<unsigned char> buf(SIZE);
fread(&buf, 1, SIZE, f);
|
by: Bobrick |
last post by:
Hi.
I'm in the process of making a GUI for a function someone else wrote,
and i've come across a type i'm unfamiliar with, namely
"std::vector<unsigned char>". I need to get the contents of this
variable into a form I can display in a text box, but i'm not sure what
to expect inside of the variable, whether I can just treat it like an
array e.t.c. Any help would be appreciated.
Thanks,
|
by: Bobrick |
last post by:
Hi.
Thanks to everyone who replied to my last post, it turns out it wasn't
the line where I was trying to treat the variable in question as an
array which was the problem, but the line above.
char temp;
std::vector<unsigned charmmessage;
while (!done){
|
by: arnuld |
last post by:
This works fine, I welcome any views/advices/coding-practices :)
/* C++ Primer - 4/e
*
* Exercise 8.9
* STATEMENT:
* write a program to store each line from a file into a
* vector<string>. Now, use istringstream to read read each line
* from the vector a word at a time.
| |
by: Andrew Wingorodov |
last post by:
i have std::vector<stringarg; for dynamic program configuration.
i need get const char* argv; for execv(3).
how i can make its simple?
there may be ready solutions?
--
www.andr.ca
|
by: eiji.anonremail |
last post by:
Hi all,
I'm facing some uncertainty with const template arguments.
Maybe someone could explain the general strategy.
#include <vector>
int main(int arc, char** argv)
{
|
by: hanna88 |
last post by:
what's the best way to convert a list of string to a vector<int>?
what i have now is for loop and iterate each char in the string
string base="";
//i have vector<int>row,vector < vector<int>row > mat;
//what i want to do with the string is that everytime char != ";"
row.pushback(str that convert to int)
|
by: Michel Caillat |
last post by:
Here is a small C++ puzzling problem which blocks me in my current developments and I will appreciate any idea or explanation.
Consider the following C++ program :
#include <stdint.h>
#include <vector>
using namespace std;
int main(int argC, char* argV) {
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |