A C function that reads an entire line from a stream. It was originally a GNU extension that was standardized in POSIX.1-2008.
Questions tagged [getline]
1801 questions
0
votes
2 answers
Number extraction from a string such as an integer or double
I am having a difficult time thinking of a way to extract a number such as an int or a double from a string extracted from the getline() function.
//Example:
string data = "";
fstream inFile;
//File contains:
"Hello today is 83.3 degrees…

user2125471
- 11
- 2
0
votes
1 answer
Trouble with printing first/last elements of the array of strings
just wondering if anyone could help me with this problem I have, the program always crashes for some reason and I'm not sure why. I'm still new to C++ so, yeah.
What it's supposed to do:
Create an array of strings with 5 possible elements.
Get 5…

NopeAvi
- 1
- 1
0
votes
3 answers
Filter input received by getline
#include
#include
#include
#include
using namespace std;
int main() {
string firstFile, secondFile, temp;
ifstream inFile;
ofstream outFile;
cout << "Enter the name of the input file" << endl;
cin >>…

Eric Hondzinski
- 65
- 10
0
votes
0 answers
Get blank line after calling Palindrome function
So I have these two functions at the top of my program:
string deletespaces(string sentence){
sentence.erase(std::remove(sentence.begin(), sentence.end(), ' '), sentence.end());
return sentence;
}
and
string checkpalindrome(string…
user2093930
0
votes
3 answers
getline(isstream, string) in C++
I'm working on learning C++, and still keep running into stupid problems as I am yet unfamiliar with C++ libraries, and common errors, etc.
right now, the following piece of my code fails:
#include
#include
#include…

Jonathan
- 541
- 4
- 9
- 19
0
votes
1 answer
Is cin the right function to use in this scenario?
Here is a small snippet of my code:
int read_prompt() {
string prompt,fname,lname,input;
int id;
cout << "customers> ";
cin >> prompt;
if (prompt.compare("add") == 0) {
cin >> id;
cin >> fname;
cin >> lname;
…

dmarzio
- 345
- 1
- 3
- 9
0
votes
1 answer
File pointer movement for getline
I have got an input file with following data
2
100
2
10 90
150
3
70 10 80
Now, I am able to read till 4th line ( 10 90) but when reading 5th line(150), the file pointer seems to be stuck at 4th line. I have tried infile.clear() just incase. How do…

Amit
- 1
- 1
- 3
0
votes
1 answer
how to check EOF of HTTP client Using fdopen() and getline()
At first am checking the arguments and creating a socket which can connect to a server and defined a file where I can write my HTTP request and when there is a data, I need to Process the line that we have read, through getline and after this I…

user2014111
- 693
- 1
- 7
- 14
0
votes
3 answers
Getline from the string (not from stringstream)
Let's say I have a std::string "55|6999|dkfdfd|". It cointains 3 parts (each is followed by |). Currently I put the string to stringstream and I use getline to recover them. However I wonder if there is a simpler solution which doesn't require…

user1873947
- 1,781
- 3
- 27
- 47
0
votes
1 answer
getline as loop condition - infinite loop
int main(int argc, char** argv)
{
ifstream input;
ofstream output;
input.open("input.txt");
output.open("output.txt");
char c;
output << "ID\tLName\tFName\tQ1 Q2 Q3 Q4 Q5 Q6 T1 T2 Final" << endl;
output <<…

user1884814
- 31
- 1
- 1
- 6
0
votes
1 answer
windows versus linux std::getline string
I have an xml file that I want to extract some specific fields from
Sample test file

forest.peterson
- 755
- 2
- 13
- 30
0
votes
2 answers
how do i read data from textfile and push back to a vector?
I have a text file, "test.txt" which stored my data as follow, there's a spacing between each delimiter field..
Code: Name: Coy
045: Ted: Coy1
054: Red: Coy2
How do i read this data from file and insert this into a vector?
vector …

user1745860
- 207
- 1
- 5
- 11
0
votes
6 answers
How to write a getline function in C?
I know that getline is C++ standard but I need to read a line of digits:
123856
and save it to an array. But how to do this without spaces between given (as input) digits? I want a user input to be:
123856 (with no spaces) and then save it to an…

yak
- 3,770
- 19
- 60
- 111
0
votes
1 answer
Extract the specific data from the file
I have a file(as text) from which I should extract all included files names.
The implementation should be in C++
What I thought to do is to read a file line after line (getline)
check if line starts from #include - how do I do that?(there could be…

YAKOVM
- 9,805
- 31
- 116
- 217
0
votes
2 answers
How to start reading some part of the text in a file once a keyword preceeding the text is found
Here's a code i wrote...pretty basic as I'm a beginner.....
The source file looks like:
Integers:
1 2 3 4 56 ...
String:
This is a string......
...(text).....
The code should read the text depending on the keywords it encounters at the…