Questions tagged [getline]

A C function that reads an entire line from a stream. It was originally a GNU extension that was standardized in POSIX.1-2008.

1801 questions
0
votes
1 answer

getline() error in C++ when using for loop

I had to write a program to calculate average speed of a car during a trip and I have to prompt the user for the names of the two cities that they were traveling between. That program worked, but the next program we had to write is an addition to…
0
votes
1 answer

Calling printf before getline causes problems. Sometimes

I have to make a shell in C, what should be a simple task is giving me trouble. The following code prints out the text and continually inputs, but only does the printf once. printf("(pid=%ld)%s$", (long int)pid,cwd); fflush(stdout); …
Dan
  • 176
  • 1
  • 11
0
votes
2 answers

C++ getline() delimitter

Hey I am trying to read in the following lines using a getline (15,0,1,#) (2,11,2,.) (3,20,0,S) I want to be able to just extract the integers as ints and the characters as char, but I have no idea how to only extract those.
0
votes
1 answer

Reading in numbers with getline

I have a line that has the format (int,int,int,char) and wish to store the three ints into x,y,z and then place the char value into that position in my 3D array. However it is skipping the first number and going to the second. Any help? void…
GoBlue_MathMan
  • 1,048
  • 2
  • 13
  • 20
0
votes
2 answers

Unexpected output when reading from getline into a non-empty string

I get confused with the "istream& getline (istream& is, string& str)"function, and according to http://www.cplusplus.com/reference/string/string/getline/, the following program: #include #include int main() { …
JavaBeta
  • 510
  • 7
  • 16
0
votes
1 answer

getline to split string manipulation error

Hey guys so I have an assignment for class where I have to split a string and manipulate it. However, when I try to split the string and assign it to an array only the first element comes and the other two don't. Please help. #include…
Arun Kalyanaraman
  • 648
  • 2
  • 10
  • 22
0
votes
1 answer

Taking output and storing it into a variable?

I have this code: string text; getline(cin ,text); istringstream iss(text); copy( istream_iterator(iss), istream_iterator(), ostream_iterator(cout,"\n") ); When I input a string like: bf "inging" filename, it…
user2757849
  • 227
  • 3
  • 4
  • 14
0
votes
2 answers

Splitting string by spaces difficulty

My code is working except for one problem, when I run it it doesn't seem to return the first string. string text; cin >> text; getline(cin ,text); istringstream iss(text); copy(istream_iterator(iss), …
user2757849
  • 227
  • 3
  • 4
  • 14
0
votes
3 answers

Problems with reading text from a file

I have this function that reads the text from a file and adds it to a string, now the weird thing is that it works fine if its a short text. But if its a longer text the string becomes empty, any help solving this problem is appreciated. string…
bryo
  • 39
  • 1
  • 6
0
votes
3 answers

Garbage value with getline

#include #include void main() { clrscr(); char c[50]; //cin>>c; cin.getline(c,50); //cout.write(c,50); cout<
0
votes
2 answers

Awk a external Command and Get line

I am trying to see whats the best way to extract the 3rd line from this command but i can't seem to get it awk 'BEGIN{while("service ipsec status" | getline x) print x}'
Luis
  • 83
  • 2
  • 10
0
votes
1 answer

recoding getline function on C

I need a function who reproduce a basic of the getline function for another program, this function should be able to read a FP properly and without a huge buffer (256 should be enough here) I have 2 problem on the code below - the function start to…
Saxtheowl
  • 4,136
  • 5
  • 23
  • 32
0
votes
1 answer

Getline string input to create a word

I have a program that receives an input and goes character through character to avoid white spaces. What I need to do now is get each one of those characters that aren't white spaces and stores them in a string as a word. Someone told me that…
baldemora
  • 72
  • 7
0
votes
5 answers

Getline reading in a csv very oddly

I am trying to read a csv using get line to extract three variables separated by commas. Name, Course, and Grade. I am reading in the first line fine but it puts in weird new line breaks and sends the format into a cluster. Here is my code…
Mike
  • 1
  • 1
  • 1
0
votes
1 answer

Strange getline behavior in c++

I have the following file: BB 7.501106 5.324115 7.997006 8.287983 11.314904 11.768281 ... And i am 100% sure that the file is ok, i have even shown newlines in vim with :set list : BB$ 7.501106 5.324115$ 7.997006 8.287983$ 11.314904…
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175