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
using getline to store string in array
This is the code:
#include
#include
#include
#include
int main()
{
char str1[100];
char str2[100];
getline(str1,100,'\n');
getline(str2,100,'\n');
return 0;
}
I want to read…

Rahul Bhojwani
- 87
- 1
- 11
0
votes
1 answer
C++ getline and if/else if statements are not working as I intended
I started learning C++ recently. I wrote this program that outputs numbers based on user input. Before I was asking the user for integers to determine the output, but then I found out that I can obtain a string from the user using getline. My…

user2530088
- 1
- 1
- 1
0
votes
1 answer
Last of word of each line needs to be skipped?
I'm trying to write a code that will skip the last word while reading txt file. I am not sure how to go about outputting the line without including the last line and the space before it. Any help would be appreciated, I'm new to c++.
0
votes
3 answers
getline C++ not getting result that is required
Compiler version is 4.2 g++
#include
#include
using namespace std;
int main()
{
string a[10];
int i;
int N;
cin>>N;
for (i=0; i
user1987296
0
votes
1 answer
C++ getline gives back some strange results
I'm trying to run this code:
string p = "Test.txt";
ifstream fid(p.c_str());
while(!fid.eof()) {
getline(fid,p);
cout << "|s|" << p << "|e|" << endl;
}
But the result put's somehow of since it is like this:
|e|line1
|e|line2
…

magu_
- 4,766
- 3
- 45
- 79
0
votes
2 answers
C++: Spaces in strings prevent me from comparing cin input.
(Sorry, I know this question has been asked [and answered] before, but none of the solutions worked for me, because something about the way my code is set up is wonky and I have no idea which part that is).
Okay, I have a function, get_cookie_type,…

Evan Johnson
- 53
- 3
0
votes
2 answers
ifstream getline does not find delim
If the ifstream::getline call does not find the delimeter I know it sets failbit but does it also clear out the buffer or does it leave the buffer intact and just set the fail bit to let you know?

csteifel
- 2,854
- 6
- 35
- 61
0
votes
1 answer
cin.getline () is not working when called the second time
In this code ,getline is not working for i =1 .but for i = 0 it is working completely fine.
What I should do to repeatedly work with the getline function.This code takes a number and checks its divisibility."numb" is taken to store the number.for i…

aroup
- 315
- 3
- 13
0
votes
2 answers
How to get a set of words with spaces as one input in C?
In a program I created I need to get some customer information to an array. Below are the codes regarding my question.
struct CustomerType
{
string fName;
string lName;
char gender;
string address;
string…

Dishon Michael
- 157
- 1
- 2
- 6
0
votes
0 answers
C++ reading values into an array on XCode
I can't figure out why the following code doesn't output properly. It's supposed to read a name and grades into an an entry of an array of students. For some reason, there are phantom entries in between the real entries, as denoted by the lines in…

Greg
- 223
- 2
- 11
0
votes
1 answer
Console output keeps crashing
Trying to solve this Problem.
I have written the code which looks like this:
#include
#include
#include
using namespace std;
int i,j,n,t;
int main()
{
cin>>t;
while(t--)
{
vector dr,rd;
string a,b;
…

classius
- 115
- 1
- 6
0
votes
1 answer
std::getline() is not ending/capturing
This does not work.
playing = true;
while (playing) {
std::string command;
std::cin.ignore(1);
std::getline(std::cin, command);
execute(command);
std::cout << "asdasd";
}
Whenever the program runs, it does not input whenever I…

Astrognome
- 303
- 3
- 9
0
votes
3 answers
read in txt file in C++
I have a .txt parameter file like this:
#Stage
filename = "a.txt";
...
#Stage
filename = "b.txt";
...
Basically I want to read one stage each time I access the parameter file.
I planed to use getline in C++ with delimiter "#Stage" to do this. Or…

colddie
- 1,029
- 1
- 15
- 28
0
votes
0 answers
getline() not waiting for user input
I have a code that is supposed to use user input to take an order of a pizza.
#include
#include
using namespace std;
int main()
{
double totalCosts = 0;
// PIZZA
cout << "What size is your first pizza?\n"
"small: …

i .
- 485
- 2
- 10
- 23
0
votes
0 answers
Enum ifstream and getline()
I've got the problem with following code. It should get the object parameters from the txt file. Of course to get enum values correctly I've made this simple getline() function. I'm keep getting errors which I've tried to repair, but I still have no…

fragon
- 3,391
- 10
- 39
- 76