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

how to copy iostream& data into string?

33
hello,
im having problem to copy the data from iostream& into string.and im not sure am i doing the right way by using getline.can anyone give hints how to solve this.

here's to make things clear:


Expand|Select|Wrap|Line Numbers
  1.  
  2. //method that reads through the stream and breaks it into words and sentence
  3.  
  4. Document*Repository::addDoc(iostream& inStream,string docId)
  5.  
  6. //test core
  7.  
  8. Repository r1;
  9. stringstream ss;
  10.  
  11. string s1 = "Hello World;"
  12.  
  13. ss.clear();
  14. ss<<s1;
  15. r1.addDoc(ss,"1")
  16.  
  17.  
  18.  
thanks in advance
Oct 20 '09 #1
5 2294
Banfa
9,065 Expert Mod 8TB
That code snippet does access iostream& and doesn't copy into a string.

It copies a string into a streamstream which looks ok to me.
Oct 20 '09 #2
hanna88
33
thanks for your reply.

@Banfa
so how can i access the copied string into streamstream should i convert it back to string in order to use string method like strtok?
Oct 20 '09 #3
Banfa
9,065 Expert Mod 8TB
If you mean should you convert it into a C string to use strtok then no. strtok is an evil function and should be avoided.

However you could convert it back into a string (the C++ variety) and use the member functions of string (find and substr) to tokenise it.
Oct 20 '09 #4
hanna88
33
the string is been passed in iostream& form and the only for me to get access on the string is getline().im not sure whether it is right by using getline() first then convert it into string in order to tokenize it.

any hint would be great! thanks again
Oct 20 '09 #5
Banfa
9,065 Expert Mod 8TB
You don't need to use getline then convert it to a string, getline can read straight into a string

string getline reference

Even so conversion to a string is still better than calling strtok.
Oct 20 '09 #6

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

Similar topics

3
by: Ken | last post by:
How do I copy data from one file to another? from $_SESSION to "fname" datafile.php has fname: $_SESSION; lname: $_SESSION; I would like to automatically copy the data to
1
by: sbh | last post by:
I need to copy data from a table on one Oracle server to another. Scenario: Need to create a stored procedure in server a, database aa that will copy data from server b, database bb, table bbb to...
3
by: thaar al_taiey | last post by:
hi their, How can i copy data in MS-SQL 2000 from one table to another with different charactristic? thanks *** Sent via Developersdex http://www.developersdex.com ***
0
by: Banx | last post by:
Hi everyone, i'm trying to copy data from a table in Pervasive database to a table in MySQL Does anyone know how to do it? :confused: Is it posible to copy data from another database prog to...
2
by: Ken | last post by:
How can I copy data from SQL to MS Access using dsn-less connection and not using SQL DTS? I have this but am stuck. I just want to do an export but can't figure out how to do a "select into". ...
0
by: eyal | last post by:
Hello, I want to open 2 workbook, , lets say workbook1 and workbook2 now I want to copy data from a sheet name "TEST" in workbook2 and paste the data to a sheet named "TEST" in workbook. now...
2
by: isa | last post by:
Hello everyone, i want to transfer/copy data from MSDE to SQL Server 2000 and from SQL Server to MSDE, through Stored Procedures , not using a "Replication", kindly tell me how i make a SP for...
2
by: deviparimala | last post by:
Hi All, I'm opening 2 notepads in my windows application. I copy data from one notepad and paste it another notepad. The data should not get pasted into the second notepad. Can I handle this...
1
by: okonita | last post by:
Hi all, I have a need to copy data from one database/schema to a different database schema. Yes, I can use export/import but that is not "elegant". Yes, I can try a redirected Restore from Backup...
0
by: Bxitty | last post by:
I have a package that works great when I run it from the SQL2000 environment. This job transfers data from SQl2005 table to a mainframe DB2 table. After I migrated the job to SQL2005 and ran...
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: 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
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...
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.