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

using getline with ifstream

the function getline is a public member of istream and cin.getline can be used.
Since ifstream is publicily derived from istream, getline shall be available in ifstream as well. However,on solaris ver 2.7, getline is not recognised.

e.g
ifstream f("a.cpp");
string s;
f.getline(s,100);

why doesn't complier recognise fstream::getline(string,int) even though istream::getline(string,int) is recognized
Feb 3 '07 #1
2 28672
horace1
1,510 Expert 1GB
the function getline is a public member of istream and cin.getline can be used.
Since ifstream is publicily derived from istream, getline shall be available in ifstream as well. However,on solaris ver 2.7, getline is not recognised.

e.g
ifstream f("a.cpp");
string s;
f.getline(s,100);

why doesn't complier recognise fstream::getline(string,int) even though istream::getline(string,int) is recognized
your string s should be a char *, e.g.
Expand|Select|Wrap|Line Numbers
  1. ifstream f("a.cpp");
  2. char s[50];
  3. f.getline(s,100);
  4.  
Feb 3 '07 #2
Ganon11
3,652 Expert 2GB
If you want to keep it as a string, I've always used

Expand|Select|Wrap|Line Numbers
  1. getline(istreamVar, stringVar);
where istreamVar is either cin or my ifstream variable, and stringVar is the string you are trying to initialize.
Feb 3 '07 #3

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

Similar topics

11
by: John | last post by:
Hello all, I am trying to read in lines into a buffer from a file. Normally I would do this very low-level, but I have come to the conclusion I must stop doing everything the hard way. So, I...
2
by: Peter Gordon | last post by:
Is using getline with a fstream reference covered in the standard? I have three C++ compilers on my system. Two of them compile the code below without warnings. The third returns the following...
1
by: tinks | last post by:
I am getting a linking error when I do something like this: ifstream dataFile; dataFile.open(dataFileName_, ios::in); while(dataFile) { dataFile.getline(buffer, MAX_DATA_FILE_LINE_LEN); //...
5
by: allspamgoeshere3 | last post by:
Hi! I'm having trouble reading text lines from a file describing the levels for a simple game I'm creating. Inside the function that reads the content of the file there is a loop that basically...
7
by: jccorreu | last post by:
I've got to read info from multiple files that will be given to me. I know the format and what the data is. The thing is each time we run the program we may be using a differnt number of files,...
3
by: Wilson | last post by:
hi, one aspect of a program i am creating needs to extract a certain line of text from a simple ".txt" file. However i can only find a way of extract everything present in the file using i/o...
3
by: Gary Wessle | last post by:
Hi I have a method A which have a loop, in that loop, another method B is called, B opens a file and does getline till found something interesting, does something with it and return void. then...
13
by: theronnightstar | last post by:
I seem to be having a problem with getline(). I have tried to find it on google, but I'm not seeing the answer. The goal of this section of code is simply to read in a line from a file to a...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.