Dear all,
I am reading a file line by line and change some fields,
I am reading the data in to a
vector <string> data_;
say:
s1
s2
s3
then I want to write these data_ to a
vector<vector <double> > f_;
so the first field in the data_ will be written into the first vector
of f_ and so on
so f_ will look like this after the first push_back():
s1 4 2090
Sorry I forgot to tell that I will convert strings to doubles before
push_back().
utab wrote: Dear all,
I am reading a file line by line and change some fields,
I am reading the data in to a
vector <string> data_;
say:
s1 s2 s3
then I want to write these data_ to a
vector<vector <double> > f_;
so the first field in the data_ will be written into the first vector of f_ and so on
so f_ will look like this after the first push_back():
s1 . . . s2 . . . s3 . . . and will be filled as I read the file repeatedly. Is that possible to use reserve() in this situation to reserve places.(But i think not because I have a vector not a built-in type in vector<vector<...> >)
Your question is not clear. Do you mean that your 2-D vector will look
like this:
data[0] = { s1, x, x, x }
data[1] = { s2, x, x, x }
data[2] = { s3, x, x, x }
Where s1, s2, & s3 are floats (not strings) and x is reserved but not
allocated? Which vector (the inner, outer, or both) do you want to use
reserve on? On which are you calling push_back?
The answers to these questions will determine the answer to your
question.
Cheers! --M
On 2006-05-25 18:57, mlimber wrote: utab wrote: Dear all,
I am reading a file line by line and change some fields,
I am reading the data in to a
vector <string> data_;
say:
s1 s2 s3
then I want to write these data_ to a
vector<vector <double> > f_;
so the first field in the data_ will be written into the first vector of f_ and so on
so f_ will look like this after the first push_back():
s1 . . . s2 . . . s3 . . . and will be filled as I read the file repeatedly. Is that possible to use reserve() in this situation to reserve places.(But i think not because I have a vector not a built-in type in vector<vector<...> >)
Your question is not clear. Do you mean that your 2-D vector will look like this:
data[0] = { s1, x, x, x } data[1] = { s2, x, x, x } data[2] = { s3, x, x, x }
Where s1, s2, & s3 are floats (not strings) and x is reserved but not allocated? Which vector (the inner, outer, or both) do you want to use reserve on? On which are you calling push_back?
The answers to these questions will determine the answer to your question.
You can use reserve on both vectors. Since f_ in this case will only
contain references to the vectors containing {s1, x,..} you can reserve
room for any number of such references.
--
Erik Wikström
--
"I have always wished for my computer to be as easy to use as my
telephone; my wish has come true because I can no longer figure
out how to use my telephone" -- Bjarne Stroustrup
Erik Wikström wrote: On 2006-05-25 18:57, mlimber wrote: utab wrote: Dear all,
I am reading a file line by line and change some fields,
I am reading the data in to a
vector <string> data_;
say:
s1 s2 s3
then I want to write these data_ to a
vector<vector <double> > f_;
so the first field in the data_ will be written into the first vector of f_ and so on
so f_ will look like this after the first push_back():
s1 . . . s2 . . . s3 . . . and will be filled as I read the file repeatedly. Is that possible to use reserve() in this situation to reserve places.(But i think not because I have a vector not a built-in type in vector<vector<...> >)
Your question is not clear. Do you mean that your 2-D vector will look like this:
data[0] = { s1, x, x, x } data[1] = { s2, x, x, x } data[2] = { s3, x, x, x }
Where s1, s2, & s3 are floats (not strings) and x is reserved but not allocated? Which vector (the inner, outer, or both) do you want to use reserve on? On which are you calling push_back?
The answers to these questions will determine the answer to your question.
You can use reserve on both vectors. Since f_ in this case will only contain references to the vectors containing {s1, x,..} you can reserve room for any number of such references.
It will not contain references to the internal vectors; it will contain
a dynamically allocated copy.
Without more information, I don't think the rest of your answer can be
termed correct. Were the OP wanting to reserve space in both the inner
and outer vectors at the start of the program, for instance, it would
not work. Since the intent was not clear, neither is the solution.
Cheers! --M This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ferran Foz |
last post by:
Hello,
I'm using ADODB.Stream to open a binary file on the server and write
it down to the browser using Response.BinaryWrite. It's working fine,
but i need to make some changes to the binary...
|
by: Dennis McFly |
last post by:
Hello,
I am running into a problem with an application that doesn't work too
well with mutliple rows. Therefore, I need a script that will return a
SINGLE row. This is what I'd like to do:
I...
|
by: Oded |
last post by:
Hello,
I'm trying to build a web form which should display a list of DB records and provide edit/insert/delete capabilities. I want to allow client manipulation of the data, including several rows...
|
by: ajay |
last post by:
Hi
I need to read data from flat files in memory and execute SQL query on
the in-memory data. I do not have an option of using a database and I
am using c# .Net to build my application. Does...
|
by: Jeff |
last post by:
For years I have been using VBA extensively for updating data to tables
after processing. By this I mean if I had to do some intensive processing
that resulted in data in temp tables, I would have...
|
by: Ben R. |
last post by:
Since the original thread is marked as answered, I thought I'd post here to
ensure visibility.
Hi John and Steven,
I'm going the dataset route as access doesn't seem to be too keen on that...
|
by: Mike Cain |
last post by:
Hi,
The Repeater control seems like exactly what I want to output rows of data
from my database. However I need to do some manipulation to the data prior
to it being output and I'm not...
|
by: holdingbe |
last post by:
Hi all,
During the update the views it shows ORA-01732: data manipulation operation not legal on this view error. this view created by only one table.
please help me....
Thanks...
|
by: filipo |
last post by:
Hello all;
I have a .csv file that contains messages exported from one discussion forum that I want to import into another forum (phpBB), but I need to do some data manipulation on the original...
|
by: Spike1980 |
last post by:
Hi,
I am trying to update a table using cursors...
I have a few if clauses... I just put the first if clause and I am trying to update the table, but it gives me an error saying "data...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |