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

How to read string with space (help please)

6
hi
i have the following code :

string addrress;
cin >> address;
cout << address;

if I enter any string with space in between , it will save the first word only.

e.g. if i enter "this is a test"

address = this

how can I make address to have the rest of the string too. please help
Dec 4 '06 #1
3 8915
shamik
5
use gets(address) instead of cin>>address

and puts(address) instead of cout<<address
Dec 4 '06 #2
shaft
6
thanks it works. but i had to declare address as Char not string. so how can i get the size or length of the Char. is like (string.size or string.length). advise me please.

regard's
Dec 4 '06 #3
Ganon11
3,652 Expert 2GB
string addrress;
cin >> address;
cout << address;
If you want to keep address as a string, use the getline function:

Expand|Select|Wrap|Line Numbers
  1. getline(istreamVar, stringVar);
where istreamVar would be cin, and stringVar is address. This will get every character in the input stream until a newline character is found. So, with your example, if you entered "this is a test", address would hold "this is a test".
Dec 4 '06 #4

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

Similar topics

1
by: Jong Choi | last post by:
Dear All, I am trying to open the file(walk5.dat) and then read the data The structures of data are 0, 0, -10, -10, 0, -8.1,-12,-10 , 0,-14,-10,-7,0, 6.096666667,-10,-10,1, ...
1
by: Venkat | last post by:
Hi, I am buried with the following issue on Linux platform, please let me know if someone can help me out. I am using ifstream to open and read the file, even i am able to open the file i am...
40
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
1
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each...
4
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void...
6
by: sghi | last post by:
Hi All, I'm new to this group and quite new to access/vba. So, shortly after beginning to write a simple application for my wife, I came across a blocking problem: I need to intercept the sql...
10
by: MLH | last post by:
I wish to give someone an A97 database they can install on their PC as a runtime application. I want them to click a button on a form (frmDocumentMyPC). I want to document as much useful...
16
by: junky_fellow | last post by:
Is there any efficcient way of removing the newline character from the buffer read by fgets() ? Is there any library function that is similar to fgets() but also tells how many bytes it read...
9
by: srikanth | last post by:
i have a text file like below, test.txt file (actually my test file file is with 10000 lines but here i tested with 3 lines) 3 06.09.2006 16:37:25 3 06.09.2006 16:40:02 3 06.09.2006 16:42:31...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.