Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 07-23-2003, 04:47 PM   #1
Beta Member
 
Join Date: Jul 2003
Posts: 5
Send a message via AIM to kompiled
Default Awkward problem with C++'s getline(cin, name) operator...

I have been working on a simple calender program in C++ and I have come upon a problem with the getline operator. My problem is I want to be able to save a string to a specific point in an array of strings. So I use "getline(cin, tempbuff)" which should take whatever input from "cin >>" and store it in the string tempbuff. However, it's not storing anything in tempbuff after the cin>>. For better review, here is my source code -> www.geocities.com/neo_centre/source.html

If you would take a look at/or compile and run it you'd probably understand what I'm talking about. My problem occurs right before the end of main(). Any reply is appreciated. Oh and btw, you may notice that the libraries I'm using are referenced with '(' rather than '<'. This is because I had to change it cuz HTML wasn't understanding the greater than brackets. It thought they were HTML tags.
__________________

kompiled is offline   Reply With Quote
Old 08-16-2003, 03:22 AM   #2
Solid State Member
 
Join Date: Aug 2003
Posts: 18
Smile

I don't know too much C++ but here the first parameter of getline is the pointer to take the new string and the second the characters-1 to be extracted.
Also, i think that the size of tmpbuff is only 3....
__________________

heat is offline   Reply With Quote
Old 08-18-2003, 03:39 PM   #3
 
Join Date: May 2003
Posts: 56
Default Try this

I reviewed your code and that the char [tempbuff]="Hi", has a size of 2 therefore.. any string larger that this size wont be stored ...

Have u tried using one letter.. or even more... to increase this size ?

Sincerely
CourtneyDS
__________________
$socket = IO::Socket::INET->new(Proto => "udp") or die "Socket error: $@\n";
$ipaddr = inet_aton($host);
$portaddr = sockaddr_in($port, $ipaddr);
send($socket, $buf, 0, $portaddr) == length($buf) or die "Can't send: $!\n";
print "Now, '$host' must be dead : )\n";
CourtneyDS is offline   Reply With Quote
Old 08-18-2003, 05:41 PM   #4
Site Team
 
David Lindon's Avatar
 
Join Date: Dec 2002
Posts: 15,233
Default Re: Try this

Quote:
Originally Posted by CourtneyDS
I reviewed your code and that the char [tempbuff]="Hi", has a size of 2 therefore.. any string larger that this size wont be stored ...

Have u tried using one letter.. or even more... to increase this size ?

Sincerely
CourtneyDS
Good to see you back courtney.
__________________
[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote
Old 09-11-2004, 06:16 AM   #5
Baseband Member
 
gelpogi's Avatar
 
Join Date: Sep 2004
Posts: 23
Default

OK, try this

cin.getline(ur_array[i],length,'\n');
//int i= is used to store the string input to the certain point of array
//length=length of string input
//'\n'=any delimiter
gelpogi is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 05:25 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0