473,397 Members | 2,099 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,397 software developers and data experts.

Split Vector

I have date and time combined in a vector and i want to split the date and time and store them in a vector again for comparision.
The below is the format of datetime vector
For example :-
25/Jul/2011:00:00:32
Feb 20 '12 #1
13 3109
weaknessforcats
9,208 Expert Mod 8TB
Why not just keep the date and time as you have it now and do any splittng inside the comparison function?

It doesn't look like you need a second vector.
Feb 20 '12 #2
Hi,
Thanks for the reply :)
I can do that in comparision function but even for that i need to split the vector datetime. My requirement is i need to see the time for a particular day... to make it brief date is constant but i need to see the time which changes so for this i want to split them.
Feb 20 '12 #3
weaknessforcats
9,208 Expert Mod 8TB
If the date is constant, aren't all the times for the same day?
Feb 20 '12 #4
yes the time is for the same day...
If i can split it then i can count how many times per day i got web hits
Feb 21 '12 #5
Banfa
9,065 Expert Mod 8TB
What is the data type that the vector contains? Is it a string or is it some binary type.

If the dates are constant (i.e. all the same) then a simple string comparison will do the job for you if you want to sort.

However having read all the posts you appear to be trying to analyse the data. If the dates are truly all the same then the number of hits per day you just be the size of the vector, no need for any analysis.

However if you have loaded the dates from a server log into a vector then presumably the dates are not all the same. You could write a simple function to use with std::transform to strip the time off the string and store in a new vector.

However if there are a very large number of entries it may be better to create a set of unique dates and then use that with std::count_if to analyse the data in the original vector because it will use less memory.
Feb 21 '12 #6
Hi,
the datatype is string.
the access log file contains data in daily basis and am storing the web hits in each vector but i got date and time in same vector which i want to split and i have huge number of web hits
Feb 21 '12 #7
Banfa
9,065 Expert Mod 8TB
OK my point here is that if you solely want the number of hits per day then that is simply the number of entries in the vector if a single file is the data for a single day. You have no need to split the strings a simple vector::size call will give the answer. In fact you do not need to even load the vector, a count of the number of lines in the log file should give the answer.

From what you have posted it is not clear why you would need to split the strings or indeed do anything to them.

However if you where also trying to get hits per hour over the day or some simlar processing they you might. However as weaknessforcats has pointed out since all the dates are the same that data is just not required, you could have a single vector with just the times in it by processing the string before you put it into the vector.

Look up string::find_first_of and string::substr, these 2 methods should enable you to do what you want.

Another option is rather than store a string to store the second in the day, the conversion is slightly harder but you could fit it into a 4 byte integer using about 50% less memory. Comparisons would be quicker too compared to the string comparisons you would have to do otherwise.
Feb 21 '12 #8
To make my requirement more clear...
First thing is i have a log file which i do consider and in that i have web hits which contains ip address , userid , date & time , link to which the Customer logs in.Now my requirement is i need to get the web hits for a particular Customer for a configurable time period. So, for this I have split the web hit by spaces and used a switch case through which i have stored each variable(ip address,userid etc) into a vector. Now in vec1 i have ip address,vec2 i have userid and so on. But here my problem is i couldn't split a vector which has date and time. If i can split it then i can compare previous vector with the present vector if the web hit is of the same customer i can retrieve the usage for a configurable time period.I need the time period seperately as i need to count the web hits for time(example 00:01:00)
Feb 21 '12 #9
weaknessforcats
9,208 Expert Mod 8TB
You would be better off placing the userid, date and time, etc in struct. Store the struct in your vector. Use another struct for the date and time an put an instance of that Date struct inside the one for the Customer's data.

Now everything is separated so you can get at it:

Expand|Select|Wrap|Line Numbers
  1. struct LogEntry
  2. {
  3.     Customer* c;
  4.     Date dt;
  5.     etc...
  6. };
  7. where
  8. struct Date
  9. {
  10.     int month;
  11.     int day;
  12.     int year;
  13.     int hh;
  14.     int mi;
  15.     int sec;
  16. };
Now you should be able to write a function that iterates the LogEntry instances in your vector and if it is the correct Customer, and the Date is within range, then...well you can go from here.

You may find that this is easier than additional vectors and frequent data parsing.
Feb 21 '12 #10
Thanks for the solution weaknessforcats but i'm not looking for struct. I dont want to use struct in my coding.so, could u please provide me a solution as i asked for splitting a vector or conversion of vector to string so that i can go in the further procedure
Feb 22 '12 #11
Banfa
9,065 Expert Mod 8TB
Thanks for the solution weaknessforcats but i'm not looking for struct. I dont want to use struct in my coding.
Why on earth not?

You are talking about having a vector full of strings and then processing each string every time you want some information and creating a new vector. That will be costly in both processor time and memory used.

If rather than a string you store a structure of values that have already been processed from the string you will in general save both time and memory.

The pseudo code for what you want is something like this

Expand|Select|Wrap|Line Numbers
  1. // Pull the log file into memory
  2. OPEN LOG
  3.  
  4. FOREACH LINE IN LOG
  5.   READ LINE
  6.   PUT LINE IN VECTOR 1
  7.  
  8. // Process data in memory
  9. FOREACH ENTRY IN VECTOR
  10.   GET ENTRY
  11.   PROCESS ENTRY INTO NEW STRING
  12.   STORE STRING IN VECTOR 2
  13.  
  14. FOREACH ENTRY IN VECTOR 2
  15.   ANALYSE DATA
  16.  
  17. PRODUCE RESULT FROM DATA ANALYSIS
  18.  
For each type of analysis you want to do you will have to repeat lines 8 - 17

What weaknessforcats is suggesting (which in my opinion is a much better solution) is

Expand|Select|Wrap|Line Numbers
  1. // Pull the log file into memory
  2. OPEN LOG
  3.  
  4. FOREACH LINE IN LOG
  5.   READ LINE
  6.   PROCESS LINE INTO STRUCTURE
  7.   PUT STRUCTURE IN VECTOR 1
  8.  
  9. // Process data in memory
  10. FOREACH ENTRY IN VECTOR 1
  11.   ANALYSE DATA
  12.  
  13. PRODUCE RESULT FROM DATA ANALYSIS
  14.  
Here for each type of analysis you want to do you will have to repeat lines 9 - 13. On the whole it will be much more efficient.

If you insist on processing a vector of strings into another vector of strings then take a look at the std::string reference, also look up std::transform from the STL algorithms which could be of use in this case.
Feb 23 '12 #12
It is not regarding split vector.
Can anyone please help me in getting a variable from one class to another class.
To make it brief... I have a class x and in that i have a method xy which has a string variable p which is declared as a local variable. I have another class y in which i want to get the string variable p.
The below is my code :-
I have Hit.cpp file which has the code as below :-

string Hit::convertDate(const string& dateString,const string& hit)
{
string timing = dateString.substr(13,20)
}

I have another code Server.cpp file which has as below :-

Hit h(hit,pMapIP2IIP,userAgent);

In Server.cpp file i want to use the variable timing and it to get processed same as it is working in Hit.cpp file.

Need quick response please !!!!
Feb 29 '12 #13
weaknessforcats
9,208 Expert Mod 8TB
Plesase start a new thread. Passing data between objects is off the subject of your split vector.
Mar 1 '12 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: zealotcat | last post by:
Hi, all: I want to implement a function (using std::string and std::vector) split a string contain special token into vector. eg: string = "alex delia john" ==> vector = "alex"; vector =...
4
by: Daniel Pomrehn | last post by:
Hello :) I've got a string in a char* variable. This string is entered by the user and it can contain some \n Now I want to split the entered text by this char into different strings. Exists...
11
by: | last post by:
Hello everyone! :-D OK, I've came across many functions for this, but none works! I need one that works like this: StringSplit(string str, string delim, vector<string> results) Either with...
23
by: Sanjay Kumar | last post by:
Folks, I am getting back into C++ after a long time and I have this simple question: How do pyou ass a STL container like say a vector or a map (to and from a function) ? function: ...
1
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled...
0
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled...
5
by: AG | last post by:
Hi, I have a vector that represent memory in my code. I would like to split it into two smaller vector, without copying it. I want the split to be "in-place", so that modifications on the two...
1
by: gdarian216 | last post by:
Okay I am writting a program that will take input from a file and store it in a string. Then the string is separated at the whitespaces and these separate strings are loaded in a vector. My problem...
4
by: shuisheng | last post by:
Dear All, I have a question. Assume #include <vector> using namespace std; class A { private:
5
mickey0
by: mickey0 | last post by:
hello, I have to read a text and I decided to split it with Scanner class. private Vector<String> splitWords(Scanner s) { Vector<String> v = new Vector<String>(); while ( s.hasNext() )...
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...
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
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
tracyyun
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...
0
isladogs
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...

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.