473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

append data to a vector

Hi,

I am trying to rewrite a c++ class wrapping wininet (windows ftp/http
lib) functions.
I do the folllowing to get the response :


while ((return_code = InternetQueryDataAvailable(hReq,
&bytes_available,0, 0) != 0) &&
bytes_available 0)
{
vector<charresponse_buffer(bytes_available);
DWORD size_read;

if ((return_code = InternetReadFile(hReq, &response_buffer[0],
bytes_available, &size_read) != 0) &&
size_read 0)
{
total_read += size_read;
m_RawData += response_buffer; //m_RawData is also a vector<char>

}
else
{
break;
}
}
As you can see I store data read in vector response_buffer and I would
like to append it to my global buffer so I tried :

m_RawData += response_buffer; but it 's not possible...
How can I do it ?
Sep 28 '07 #1
9 2425
mosfet wrote:
Hi,

I am trying to rewrite a c++ class wrapping wininet (windows ftp/http
lib) functions.
I do the folllowing to get the response :


while ((return_code = InternetQueryDataAvailable(hReq,
&bytes_available,0, 0) != 0) &&
bytes_available 0)
{
vector<charresponse_buffer(bytes_available);
DWORD size_read;

if ((return_code = InternetReadFile(hReq, &response_buffer[0],
bytes_available, &size_read) != 0) &&
size_read 0)
{
total_read += size_read;
m_RawData += response_buffer; //m_RawData is also a vector<char>

}
else
{
break;
}
}
As you can see I store data read in vector response_buffer and I would
like to append it to my global buffer so I tried :

m_RawData += response_buffer; but it 's not possible...
How can I do it ?
What makes you think that += is defined for vector<char>? Have you
tried RTFM? It helps, you know.

Try

m_RawData.insert(m_RawData.end(),
response_buffer.begin(), response_buffer.end());

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 28 '07 #2
On 2007-09-28 15:18, mosfet wrote:
Hi,

I am trying to rewrite a c++ class wrapping wininet (windows ftp/http
lib) functions.
I do the folllowing to get the response :


while ((return_code = InternetQueryDataAvailable(hReq,
&bytes_available,0, 0) != 0) &&
bytes_available 0)
{
vector<charresponse_buffer(bytes_available);
DWORD size_read;

if ((return_code = InternetReadFile(hReq, &response_buffer[0],
bytes_available, &size_read) != 0) &&
size_read 0)
{
total_read += size_read;
m_RawData += response_buffer; //m_RawData is also a vector<char>

}
else
{
break;
}
}
As you can see I store data read in vector response_buffer and I would
like to append it to my global buffer so I tried :

m_RawData += response_buffer; but it 's not possible...
How can I do it ?

m_RawData.insert(response_buffer.begin(), response_buffer.end(),
m_RawData.end());

This will insert all elements in response_buffer at the end of
m_RawData. Notice that if response_buffer is large it you might gain
some speed by doing

m_RawData.reserve(m_RawData.size + response_Buffer.size());

before inserting.

--
Erik Wikström
Sep 28 '07 #3
Erik Wikström wrote:
[..]
Couple of nits:
m_RawData.insert(response_buffer.begin(), response_buffer.end(),
m_RawData.end());
m_RawData.end() has to be the first argument. The trouble is, if the
two vectors are of the same type, this will even compile, but most
likely will have undefined behaviour.
>
This will insert all elements in response_buffer at the end of
m_RawData. Notice that if response_buffer is large it you might gain
some speed by doing

m_RawData.reserve(m_RawData.size + response_Buffer.size());
m_RawData.reserve(m_RawData.size() + ..

(size is a function, needs the argument list)
>
before inserting.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 28 '07 #4
On 2007-09-28 16:11, Victor Bazarov wrote:
Erik Wikstr�m wrote:
>[..]

Couple of nits:
> m_RawData.insert(response_buffer.begin(), response_buffer.end(),
m_RawData.end());

m_RawData.end() has to be the first argument. The trouble is, if the
two vectors are of the same type, this will even compile, but most
likely will have undefined behaviour.
Yes, the last two iterators must not be iterators into the container on
which insert was called.

--
Erik Wikström
Sep 28 '07 #5

"mosfet" <jo******@anonymous.orgwrote in message
news:46***********************@news.free.fr...
while ((return_code = InternetQueryDataAvailable(hReq, &bytes_available,0,
0) != 0) &&
bytes_available 0)
{
vector<charresponse_buffer(bytes_available);
DWORD size_read;

if ((return_code = InternetReadFile(hReq, &response_buffer[0],
bytes_available, &size_read) != 0) &&
size_read 0)
{
total_read += size_read;
m_RawData += response_buffer; //m_RawData is also a vector<char>

}
else
{
break;
}
}
As you can see I store data read in vector response_buffer and I would
like to append it to my global buffer so I tried :

m_RawData += response_buffer; but it 's not possible...
How can I do it ?
What type is m_RawData?
Sep 28 '07 #6

"duane hebert" <sp**@flarn.comwrote in message
news:Hy*******************@weber.videotron.net...
>
"mosfet" <jo******@anonymous.orgwrote in message
news:46***********************@news.free.fr...
>while ((return_code = InternetQueryDataAvailable(hReq,
&bytes_available,0, 0) != 0) &&
bytes_available 0)
{
vector<charresponse_buffer(bytes_available);
DWORD size_read;

if ((return_code = InternetReadFile(hReq, &response_buffer[0],
bytes_available, &size_read) != 0) &&
size_read 0)
{
total_read += size_read;
m_RawData += response_buffer; //m_RawData is also a vector<char>

}
else
{
break;
}
}
As you can see I store data read in vector response_buffer and I would
like to append it to my global buffer so I tried :

m_RawData += response_buffer; but it 's not possible...
How can I do it ?

What type is m_RawData?
You might want to read the whole post again... especially where it tells you
what type that is. :-)

-Howard

Sep 28 '07 #7
>>As you can see I store data read in vector response_buffer and I would
>>like to append it to my global buffer so I tried :

m_RawData += response_buffer; but it 's not possible...
How can I do it ?

What type is m_RawData?

You might want to read the whole post again... especially where it tells
you what type that is. :-)
From the beginning of this thread, all that I see is the line
above referring to it as "my global buffer" but I don't
see it mentioned that it's also a vector or whatever.
Oct 1 '07 #8

"duane hebert" <sp**@flarn.comwrote in message
news:hQ*******************@wagner.videotron.net...
>>>As you can see I store data read in vector response_buffer and I would
like to append it to my global buffer so I tried :

m_RawData += response_buffer; but it 's not possible...
How can I do it ?

What type is m_RawData?

You might want to read the whole post again... especially where it tells
you what type that is. :-)

From the beginning of this thread, all that I see is the line
above referring to it as "my global buffer" but I don't
see it mentioned that it's also a vector or whatever.

in the code, almost at the end...
>m_RawData += response_buffer; //m_RawData is also a vector<char>


Oct 1 '07 #9

"duane hebert" <sp**@flarn.comwrote in message
news:hQ*******************@wagner.videotron.net...
>>>As you can see I store data read in vector response_buffer and I would
like to append it to my global buffer so I tried :

m_RawData += response_buffer; but it 's not possible...
How can I do it ?

What type is m_RawData?

You might want to read the whole post again... especially where it tells
you what type that is. :-)

From the beginning of this thread, all that I see is the line
above referring to it as "my global buffer" but I don't
see it mentioned that it's also a vector or whatever.
It's in a comment, right about the middle of the post:
m_RawData += response_buffer; //m_RawData is also a vector<char>
-Howard

Nov 15 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gernot Frisch | last post by:
Hi, how can I append the contents of one vector to another? std::vector <int> a, b; a.push_back(3); a.push_back(4); b.push_back(5); b.push_back(7); a+=b;
5
by: Phil Endecott | last post by:
Dear All, I have some code that first populates a std::set, and subsequently does a mixture of tests-for-presence and deletions. As I understand it, populating the set will be O(N log N), since...
3
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
4
by: bcomeara | last post by:
I am writing a program which needs to include a large amount of data. Basically, the data are p values for different possible outcomes from trials with different number of observations (the p...
12
by: vj | last post by:
I am using Borland C++. I run a program which generates output data files, say 'Voltage.dat', 'Current.dat'. I have a variable in my code (say N), and for various values of N (for each value of...
2
by: kvnil | last post by:
Cheers, I've been struggling all day today with this, maybe you could give me some useful pointers. I would like to (elegantly) concatenate a string out of all node values in a map. I have to...
3
by: Francogrex | last post by:
Hello, I am new to C++, have some knowledge of programming in splus(statistics). I am trying to append values output by a loop (code below) into a vector (by appending value), that I can eventually...
1
by: Rob | last post by:
How would I do this? I want to be able to handle vectors of many different types of data and vectors that can contain any number of other vectors of data. Currently, I have a templated...
10
by: oktayarslan | last post by:
Hi all; I have a problem when inserting an element to a vector. All I want is reading some data from a file and putting them into a vector. But the program is crashing after pushing a data which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.