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

how to op text file use stl string?

hey
now i have a problem,for me a c++ beginner.so i need ur help?

here i have a text file from the copy of excel data,like this:

================================================== =====apple====pear===
First XXZHYY3A(Lily) 0 20 8 0 0 7 XXZHYY3A£¨Lily£© 8 0 0 8 8 8
XXZHYY3A£¨huang£© 7 0 0 7 7 5 Senco XXZHYY3B(huang) 22 22 3.65222
22 4 XXZHYY11A£¨cheng£© 70¸ö 60 9.96 7 70
Third XSJ14B(huang) 20 20 6.6666 20 20 5 XSJ14B(Lily) 23 23 7.66659 23
23 8 XXZHYY6(huang) 26 30 9.9999 26 26 9
.......................and it is a big txt file.
================================================== ====================
first,i want to make it like this:

================================================== =====apple====pear===
First XXZHYY3A(Lily) 0 20 8 0 0 7
First XXZHYY3A£¨Lily£© 8 0 0 8 8 8
First XXZHYY3A£¨huang£© 7 0 0 7 7 5 Senco XXZHYY3B(huang) 22 22
3.652 22 22 4
Senco XXZHYY11A£¨cheng£© 70¸ö 60 9.96 7 70
Third XSJ14B(huang) 20 20 6.6666 20 20 5
Third XSJ14B(Lily) 23 23 7.66659 23 23 8
Third XXZHYY6(Lily) 26 30 9.9999 26 26 9
.......................and it is a big txt file.
================================================== ====================
how can i implica it usin STL,or another fast way,is it vector can
implic it?

and the second,i want to select the line that include First &&Lily ,
Lily && Third ,and so on ,
and then i want to get ,for example:
Lily first apple = 0 + 8 pear = 7 + 8
Lily Third apple = 23 + 26 pear =8 + 9

Do u know what i mean?

waiting for ur help !

thanks advan!

May 11 '07 #1
3 1580
On May 10, 10:06 pm, Chelong <hl.systemthin...@gmail.comwrote:
hey
now i have a problem,for me a c++ beginner.so i need ur help?

here i have a text file from the copy of excel data,like this:

================================================== =====apple====pear===
First XXZHYY3A(Lily) 0 20 8 0 0 7 XXZHYY3A£¨Lily£© 8 0 0 8 8 8
XXZHYY3A£¨huang£© 7 0 0 7 7 5 Senco XXZHYY3B(huang) 22 22 3.652 22
22 4 XXZHYY11A£¨cheng£© 70¸ö 60 9.96 7 70
Third XSJ14B(huang) 20 20 6.6666 20 20 5 XSJ14B(Lily) 23 23 7.66659 23
23 8 XXZHYY6(huang) 26 30 9.9999 26 26 9
......................and it is a big txt file.
================================================== ====================
first,i want to make it like this:

================================================== =====apple====pear===
First XXZHYY3A(Lily) 0 20 8 0 0 7
First XXZHYY3A£¨Lily£© 8 0 0 8 8 8
First XXZHYY3A£¨huang£© 7 0 0 7 7 5 Senco XXZHYY3B(huang) 22 22
3.652 22 22 4
Senco XXZHYY11A£¨cheng£© 70¸ö 60 9.96 7 70
Third XSJ14B(huang) 20 20 6.6666 20 20 5
Third XSJ14B(Lily) 23 23 7.66659 23 23 8
Third XXZHYY6(Lily) 26 30 9.9999 26 26 9
......................and it is a big txt file.
================================================== ====================
how can i implica it usin STL,or another fast way,is it vector can
implic it?

and the second,i want to select the line that include First &&Lily ,
Lily && Third ,and so on ,
and then i want to get ,for example:
Lily first apple = 0 + 8 pear = 7 + 8
Lily Third apple = 23 + 26 pear =8 + 9

Do u know what i mean?

waiting for ur help !

thanks advan!
Start with the basics, assuming a file that looks like this:
string1
string2
string3

How can you read each line and store these in a std::vector<
std::string >?
Hint:
a) #include <fstream>
b) open a std::ifstream to the target file and
c) use std::getline(...) to read one line at a time into a std::string
buffer.
d) push_back() the contents of the buffer onto the std::vector<
std::string >.

Then display each std::string element to the screen to prove it worked
(by iterating through the vector's elements).
That should be doable without expending a huge amount of effort. If
you can read and store one string, you can store 10,000 or more of
them.

The Excel data:
Analyze the fields and decide what types (std::string, int, double,
long, etc) each field might require. In other words, how must each
field be stored in the Record?
Then write a class that reflects the structure of the record involved.

class Record
{
...
};

Prove that you can initilaize and store an instance of that
record( don't worry about reading these from a file now).
Record record("Lily", 0, 20, 8, 0, 0, 7); //or whatever...
and display the record using std::cout (prefereably using a global
op<< overload).

Its all about methodology. One step at a time. Its the same principle
if you are new to a language or if you have 20 years experience. Once
you can store one Record, you can store any number of these:
std::vector< Record records;
The Record class needs to be copyable and assigneable to satisfy the
requirements of a dynamic container like a std::vector. (what does
that mean?)

To parse the Excel data:
Once you get this far, you can start zeroing in on the problem at
hand: reading and storing the tabulated data.
Keep it simple, use a file with only one single Record to parse with:
First XXZHYY3A(Lily) 0 20 8 0 0 7
May 11 '07 #2
On May 11, 3:06 am, Chelong <hl.systemthin...@gmail.comwrote:
hey
now i have a problem,for me a c++ beginner.so i need ur help?

here i have a text file from the copy of excel data,like this:

================================================== =====apple====pear===
First XXZHYY3A(Lily) 0 20 8 0 0 7 XXZHYY3A£¨Lily£© 8 0 0 8 8 8
XXZHYY3A£¨huang£© 7 0 0 7 7 5 Senco XXZHYY3B(huang) 22 22 3.652 22
22 4 XXZHYY11A£¨cheng£© 70¸ö 60 9.96 7 70
Third XSJ14B(huang) 20 20 6.6666 20 20 5 XSJ14B(Lily) 23 23 7.66659 23
23 8 XXZHYY6(huang) 26 30 9.9999 26 26 9
......................and it is a big txt file.
================================================== ====================
first,i want to make it like this:

================================================== =====apple====pear===
First XXZHYY3A(Lily) 0 20 8 0 0 7
First XXZHYY3A£¨Lily£© 8 0 0 8 8 8
First XXZHYY3A£¨huang£© 7 0 0 7 7 5 Senco XXZHYY3B(huang) 22 22
3.652 22 22 4
Senco XXZHYY11A£¨cheng£© 70¸ö 60 9.96 7 70
Third XSJ14B(huang) 20 20 6.6666 20 20 5
Third XSJ14B(Lily) 23 23 7.66659 23 23 8
Third XXZHYY6(Lily) 26 30 9.9999 26 26 9
......................and it is a big txt file.
================================================== ====================
how can i implica it usin STL,or another fast way,is it vector can
implic it?

and the second,i want to select the line that include First &&Lily ,
Lily && Third ,and so on ,
and then i want to get ,for example:
Lily first apple = 0 + 8 pear = 7 + 8
Lily Third apple = 23 + 26 pear =8 + 9

Do u know what i mean?

waiting for ur help !

thanks advan!
It would be best to save the excel data as csv format (Comma Separated
Values). This will make it easier to parse, as you are separating
records on newlines and fields on commas.

May 11 '07 #3
On 5ÔÂ11ÈÕ, ÏÂÎç6ʱ16·Ö, Keith Halligan <keith.halli...@gmail.comwrote:
On May 11, 3:06 am, Chelong <hl.systemthin...@gmail.comwrote:


hey
now i have a problem,for me a c++ beginner.so i need ur help?
here i have a text file from the copy of excel data,like this:
================================================== =====apple====pear===
First XXZHYY3A(Lily) 0 20 8 0 0 7 XXZHYY3A£¨Lily£© 8 0 0 8 8 8
XXZHYY3A£¨huang£© 7 0 0 7 7 5 Senco XXZHYY3B(huang) 22 22 3.652 22
22 4 XXZHYY11A£¨cheng£© 70¸ö 60 9.96 7 70
Third XSJ14B(huang) 20 20 6.6666 20 20 5 XSJ14B(Lily) 23 23 7.66659 23
23 8 XXZHYY6(huang) 26 30 9.9999 26 26 9
......................and it is a big txt file.
================================================== ====================
first,i want to make it like this:
================================================== =====apple====pear===
First XXZHYY3A(Lily) 0 20 8 0 0 7
First XXZHYY3A£¨Lily£© 8 0 0 8 88
First XXZHYY3A£¨huang£© 7 0 0 7 75 Senco XXZHYY3B(huang) 22 22
3.652 22 22 4
Senco XXZHYY11A£¨cheng£© 70¸ö 60 9.96 7 70
Third XSJ14B(huang) 20 20 6.6666 20 20 5
Third XSJ14B(Lily) 23 23 7.66659 23 23 8
Third XXZHYY6(Lily) 26 30 9.9999 26 26 9
......................and it is a big txt file.
================================================== ====================
how can i implica it usin STL,or another fast way,is it vector can
implic it?
and the second,i want to select the line that include First &&Lily ,
Lily && Third ,and so on ,
and then i want to get ,for example:
Lily first apple = 0 + 8 pear = 7 + 8
Lily Third apple = 23 + 26 pear =8 + 9
Do u know what i mean?
waiting for ur help !
thanks advan!

It would be best to save the excel data as csv format (Comma Separated
Values). This will make it easier to parse, as you are separating
records on newlines and fields on commas.- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -
================================================== =
thank u very much ! i will try it that!

May 12 '07 #4

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

Similar topics

14
by: Joe | last post by:
Hello All: I am trying to dynamically populate a web page with literal content and controls (textboxes and checkboxes (and eventually two buttons - the buttons do not appear in the code yet). I...
7
by: Chris | last post by:
Hi I can use a text file as a datasource but am unable to get the datatable to see the text file as having multiple columns. Everything gets put into the first column in the datatable. Sample of...
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
0
by: richardkreidl | last post by:
I have the following hash script that I use to compare two text files. 'Class Public Class FileComparison Public Class FileComparisonException Public Enum ExceptionType U 'Unknown A 'Add...
3
by: bbepristis | last post by:
Hey all I have this code that reads from one text file writes to another unless im on a certian line then it writes the new data however it only seems to do about 40 lines then quits and I cant...
1
by: Jerry John | last post by:
I am working in ASP.NET with C#. I have a text file which contains datas with delimiters. For example:- MSH|^~\$|DISCHARGE|CLAY COUNTY MEMORIAL|||200502110939| I also have an XML file created...
7
by: Malcolm | last post by:
This is a program to convert a text file to a C string. It is offered as a service to the comp.lang.c community. Originally I thought it would be a five minute job to program. In fact there are...
2
by: Killer42 | last post by:
The Input #1 statement simply reads in one line from a text file (in this case you INI file) and places the values from it into one or more variables. So what you are reading in this statement is...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
Oralloy
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,...
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...

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.