473,837 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A Question about getline

Getline has a delimiter character parameter that is used to say when input
should stop. (std::cin.getli ne)

However what do you do if you have multiple conditions/character on which
you wish to stop line input?

Jul 22 '05 #1
6 3109
JustSomeGuy wrote:
Getline has a delimiter character parameter that is used to say when input
should stop. (std::cin.getli ne)
However what do you do if you have multiple conditions/character on which
you wish to stop line input?


You write a function that do what you need.

--
Salu2
Jul 22 '05 #2

"JustSomeGu y" <no**@nottellin g.com> wrote in message
news:T5D5d.1157 73$%S.55430@pd7 tw2no...
Getline has a delimiter character parameter that is used to say when input
should stop. (std::cin.getli ne)

However what do you do if you have multiple conditions/character on which
you wish to stop line input?


Write a function. For instance you can read one character at a time until
you hit one of you multiple conditions/characters.

john
Jul 22 '05 #3

"John Harrison" <jo************ *@hotmail.com> wrote in message
news:2r******** *****@uni-berlin.de...

"JustSomeGu y" <no**@nottellin g.com> wrote in message
news:T5D5d.1157 73$%S.55430@pd7 tw2no...
Getline has a delimiter character parameter that is used to say when input should stop. (std::cin.getli ne)

However what do you do if you have multiple conditions/character on which you wish to stop line input?

Write a function. For instance you can read one character at a time until
you hit one of you multiple conditions/characters.

Ya thats kinda what I thought to.. but was just trying to see if there
was something I was missing.. Know what I mean?

Do you recommend that I write my own class and extent on basic_istream?
john


Jul 22 '05 #4

"JustSomeGu y" <no**@nottellin g.com> wrote in message
news:vGE5d.5390 77$gE.434615@pd 7tw3no...

"John Harrison" <jo************ *@hotmail.com> wrote in message
news:2r******** *****@uni-berlin.de...

"JustSomeGu y" <no**@nottellin g.com> wrote in message
news:T5D5d.1157 73$%S.55430@pd7 tw2no...
Getline has a delimiter character parameter that is used to say when input should stop. (std::cin.getli ne)

However what do you do if you have multiple conditions/character on which you wish to stop line input?


Write a function. For instance you can read one character at a time until you hit one of you multiple conditions/characters.

Ya thats kinda what I thought to.. but was just trying to see if there
was something I was missing.. Know what I mean?

Do you recommend that I write my own class and extent on basic_istream?


No need. Just write a function. One possible method would be:

Use 'getline()' with some 'default' delimiter character (use one
from the set of delimiters you want to use).

Apply 'std::find_firs t_of()' to the string written by 'getline()'.

-Mike
Jul 22 '05 #5
On Sun, 26 Sep 2004 19:23:07 GMT in comp.lang.c++, "JustSomeGu y"
<no**@nottellin g.com> wrote,
Do you recommend that I write my own class and extent on basic_istream?


Heck no.

I might recommend that you write a more elaborate substitute for
std::getline(st d::istream &, std::string &, etc.) like has already been
suggested.

I might recommend you call std::getline and then subject the line of
input to further machinations like in
http://groups.google.com/gr*********....earthlink.net

What are you trying to accomplish?

Jul 22 '05 #6

"JustSomeGu y" <no**@nottellin g.com> wrote in message
news:vGE5d.5390 77$gE.434615@pd 7tw3no...

"John Harrison" <jo************ *@hotmail.com> wrote in message
news:2r******** *****@uni-berlin.de...

"JustSomeGu y" <no**@nottellin g.com> wrote in message
news:T5D5d.1157 73$%S.55430@pd7 tw2no...
> Getline has a delimiter character parameter that is used to say when input > should stop. (std::cin.getli ne)
>
> However what do you do if you have multiple conditions/character on which > you wish to stop line input?
>


Write a function. For instance you can read one character at a time until
you hit one of you multiple conditions/characters.

Ya thats kinda what I thought to.. but was just trying to see if there
was something I was missing.. Know what I mean?

Do you recommend that I write my own class and extent on basic_istream?


No, not at all, why would you do that? Just write a function.

Suppose you want to read upto the next comma or newline

std::string my_getline(std: :istream& in)
{
char ch;
std::string res;
while (in.get(ch) && ch != ',' && ch != '\n')
res += ch;
return res;
}

Untested code.

john
Jul 22 '05 #7

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

Similar topics

2
6052
by: seia0106 | last post by:
Hello I am writing a function to read a binary file. Here is a part of code #include <fstream> .. .. BYTE *pData; long lDataLen; pms->GetPointer(&pData); lDataLen = pms->GetSize(); // Read one line at a time till end of file..
2
3563
by: Vikram | last post by:
Hi, I don't remember if it happened previously, but nowadays I'm having problem with using cin.getline function and cin>> function simultaneously. I have Visual Studio 6. If I use cin.getline function at first and then I use the cin>> function then the next time cin.getline function does not work.
5
7753
by: vknid | last post by:
Hello, I have a question. Its probably a very newbish question so please be nice hehe. =D I have been reading through C++ Programming Fundamentals, and have come a crossed an example program that shows how to use the 'getline' function. It said: "The getline function allows you to specify how many bytes you will get from the users input. Each character the user's types takes up one byte. So if, in the getline function, you specify...
1
2152
by: ma740988 | last post by:
Consider: ifstrem MyFile("extractMe.txt"); string Str; getline(MyFile, Str); getline above extracts the contents of MyFile and place into the string object. Deduced using FROM/TO logic I could state getline's first parameter supports "FROM". The second parameter supports "TO". // later
10
5620
by: Skywise | last post by:
I keep getting the following error upon compiling: c:\c++ files\programs\stellardebug\unitcode.h(677) : error C2664: 'class istream &__thiscall istream::getline(char *,int,char)' : cannot convert parameter 1 from 'const char *' to 'char *' Conversion loses qualifiers I have a data file called Standard.udf The Data File (not the problem): The data in the file is in text format, and was created using a function in this program with...
18
8266
by: Amadeus W. M. | last post by:
I'm trying to read a whole file as a single string, using the getline() function, as in the example below. I can't tell what I'm doing wrong. Tried g++ 3.2, 3.4 and 4.0. Thanks! #include <iostream> #include <fstream> #include <cstdlib> #include <string>
2
10580
by: Assertor | last post by:
Hi, All. (VC++6.0) I found some strange thins when using getline() and seekg() of std::ifstream. After the file position of an open file was shift to the end of the file, seekg() did not work rightly. (i.e. I could not move the file position to the begin or some position using seekg())
11
427
by: Key9 | last post by:
Hi all This is an simple app : read cin and print to cout I want it's action like "cat" with out arguement. #include <iostream> #include <string> using namespace std;
6
2386
by: bryant058 | last post by:
#include<iostream> #include<cstring> #include<string> #include<iomanip> using namespace std; int main() { string s; char *tokenptr; int space;
0
10902
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10583
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10286
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9420
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7824
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5680
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4481
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.