473,387 Members | 1,530 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,387 software developers and data experts.

Convert vector<float> to vector<double>

Dear experts.

I have a vector<float> and want to convert that to a vector<double>. I
optimistically tried:

#include <vector>
#include <iostream>
using namespace std;

int main() {

vector<float> vFloats;
vFloats.push_back(1.0);
vFloats.push_back(2.0);
vector<double> vDoubles = static_cast<vector<double> >( vFloats);

}

But it gave the following errors:

cast.cpp: In function `int main()':
cast.cpp:10: error: no matching function for call to `std::vector<double,
std::allocator<double> >::vector(std::vector<float, std::allocator<float>
&)'

/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0
bits/stl_vector.h:220: note: candidates are: std::vector<_Tp,
_Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = double, _Alloc
= std::allocator<double>]
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0
bits/stl_vector.h:206: note: std::vector<_Tp,
_Alloc>::vector(size_t) [with _Tp = double, _Alloc =
std::allocator<double>]
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0
bits/stl_vector.h:193: note: std::vector<_Tp,
_Alloc>::vector(size_t, const _Tp&, const typename std::_Vector_base<_Tp,
_Alloc>::allocator_type&) [with _Tp = double, _Alloc =
std::allocator<double>]
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0
bits/stl_vector.h:182: note: std::vector<_Tp,
_Alloc>::vector(const typename std::_Vector_base<_Tp,
_Alloc>::allocator_type&) [with _Tp = double, _Alloc =
std::allocator<double>]

I can only derive from them that there is no casting method available. It
mentions some candidates but I wouldn't know how to use them.

Is there some simple way to cast the vector or do I just have to write my
own conversion routine?

Regards, Pepijn Kenter.

Jul 22 '05 #1
2 11375
Pepijn Kenter wrote:
Dear experts.

I have a vector<float> and want to convert that to a vector<double>. I
optimistically tried:

#include <vector>
#include <iostream>
using namespace std;

int main() {

vector<float> vFloats;
vFloats.push_back(1.0);
vFloats.push_back(2.0);
vector<double> vDoubles = static_cast<vector<double> >( vFloats);

}

But it gave the following errors:

[...]

I can only derive from them that there is no casting method available. It
mentions some candidates but I wouldn't know how to use them.

Is there some simple way to cast the vector or do I just have to write my
own conversion routine?


Just declare it and initialise:

vector<double> vDoubles(vFloats.begin(), vFloats.end());

Victor
Jul 22 '05 #2
Victor Bazarov wrote:
Pepijn Kenter wrote:
Dear experts.

I have a vector<float> and want to convert that to a vector<double>. I
optimistically tried:

#include <vector>
#include <iostream>
using namespace std;

int main() {

vector<float> vFloats;
vFloats.push_back(1.0);
vFloats.push_back(2.0);
vector<double> vDoubles = static_cast<vector<double> >( vFloats);

}

But it gave the following errors:

[...]

I can only derive from them that there is no casting method available. It
mentions some candidates but I wouldn't know how to use them.

Is there some simple way to cast the vector or do I just have to write my
own conversion routine?


Just declare it and initialise:

vector<double> vDoubles(vFloats.begin(), vFloats.end());

Victor


That is what I was looking for. Thanks.

Pepijn.

Jul 22 '05 #3

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

Similar topics

18
by: Active8 | last post by:
I put the bare essentials in a console app. http://home.earthlink.net/~mcolasono/tmp/degub.zip Opening output.fft and loading it into a vector<float> screws up, but input1.dat doesn't. It does...
4
by: Amit | last post by:
Hi, I was wondering how to define the + and = operator for a vector of double or float and do I need to define it explicitly? does it not get defined automatically(like copy constructor) if one...
10
by: bluekite2000 | last post by:
and why doesnt the standard vector have such conversion available?
0
by: keith bannister via .NET 247 | last post by:
(Type your message here) -------------------------------- From: keith bannister Hi, I'm new to .net (as of last week) but here goes. I want to serialize/deserialize a file the conforms...
9
by: richard_lavoie | last post by:
Hi, I have something like this: vector<floatvec1; and I want to cast it, so I use vector vec2<double= static_cast< vector<double(vec1); I always become a error: syntax error before `>'...
1
by: perroe | last post by:
Hi I have a array of complex numbers that are stored in a simple double array. This is done since the array is part of an wrapper for an external C library, and the imaginary part of the first...
32
by: T. Crane | last post by:
Hi, I'm struggling with how to initialize a vector<vector<double>> object. I'm pulling data out of a file and storing it in the vector<vector<double>object. Because any given file will have a...
1
by: mathieu | last post by:
Hi there, I am dealing with the following problem: I need to convert a std::vector<T(where T can be any interget type: char, short, ushort) by applying a linear transform (a,b), following; ...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.