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
1 answer
while(getline) is not executing when in VTK program
Basically, I have written the following code to try to take a testdata file with comma seperated values in order to put the individual values into a multidimensional array and then later put them into VTK's table (Visualisation Toolkit). up until…

Daniel Takyi
- 159
- 1
- 9
0
votes
1 answer
Using getline in an implementation file while the istream is in the main
I need to use the function getline to be able to read in the spaces within a string. Currently, I'm reading word by word and any space will input the next word into a different variable. A small extract of the code is as below.
istream & operator…

Wang MingKang
- 15
- 5
0
votes
2 answers
cin.getline() without using string size
Is it possible to use cin.getline() without denoting an array size?
That is, with the following pseudo-code:
char array[15];
cin.getline(array,'.'); // '.' Is the delimiter.
Will this work?

Harjyot Singh
- 19
- 1
- 3
0
votes
1 answer
getline is assigning no value to a string object
#include
#include
#include
using namespace std;
int main()
{
//YOUR_CODE
string word;
cout << "enter a word: ";
getline(cin, word);
int middle = word.length();
middle = middle/2;
if(middle % 2 == 0)
{
middle =…

ActionON
- 106
- 1
- 9
0
votes
2 answers
reading a line from a file and put it in a string (with fstream)
i want to read a file and put each line in a string (each line contains a single word)
i've used getline but it doesn't work neither does the >> command.
here's my code:
(i'm using visual studio)
string device_kind;
ifstream…

user3033190
- 11
- 1
- 1
0
votes
2 answers
How to parse a line from the text file
So we have a text file with the following data:
Year - Make - Model - Price
2011 Chevrolet Tahoe $30588
There is only 1 space between everything. There is a Dollar Sign ($) in front of the price. We still have to have miles in our code, even if…
0
votes
2 answers
Reading Data from a Text File and Ignoring Others
For a small portion of my project, I'm supposed to extract data from a text file using cin which my program will know where to cin from based on command line arguments. My issue is how to extract the four pieces of data and ignore the commas. For…

James Wilks
- 740
- 1
- 8
- 20
0
votes
1 answer
program skip over getline
I am suppose to create a program such that when 'y' is entered it will execute the code in the first do-while loop. however, when 'y' is entered it just skips over the chunk of codes!
Enter a phone symbols:
a
2
Continue (Y/y): y
Enter a phone…

Isabella Chan
- 41
- 1
- 10
0
votes
2 answers
cin error in C++
I am writing a program that will calculate password strength according to two formulas. It requires the user to enter 2 passwords, one being eight characters or less and the other being 20 characters or more. The first parts executes with out…

user3064203
- 103
- 1
- 2
- 7
0
votes
1 answer
Getting the Average of grayscale color from an ascii image
#include
#include
#include
using namespace std;
//Function Prototypes ***************************
bool openFile(fstream &inFile);
void validateFileData(fstream &inFile, int& numRows, int& numCols);
double…
0
votes
1 answer
using two getline(cin,s) in c++
There's something wrong with my code. I typed something and pressed enter after seeing "the first string"on the screen but I saw a empty new line instead of "the second string". Then I typed something again and pressed enter again. Then I had no…

Kevin
- 27
- 5
0
votes
2 answers
Something interfering with the getline function?
I'm new to code and this website, so please forgive me if I'm overlooking something obvious. I've been trying to write a short little game in c++, and I need to take in user input. I want to take in more than one word so the cin>> command my book…

Hammurabi8
- 35
- 1
- 4
0
votes
1 answer
Removing Whitespace from string in C++
I am trying to do something that I imagine is quite straightforward but I am new to C/C++ so it is proving a little bit tricky.
Essentially I am trying to remove a single whitespace from data contained within a .txt. Each piece of data is on a…

AimSkyward
- 145
- 3
- 12
0
votes
2 answers
Threaded reading of files in C++
I have written a program (using FFTW) to perform Fourier transforms of some data files written in OpenFOAM.
The program first finds the paths to each data file (501 files in my current example), then splits the paths between threads, such that…

chrisb2244
- 2,940
- 22
- 44
0
votes
2 answers
Add some letters before and after string in C
I need to read from user some text and then print out the same text, with " at the beginning and " at the end of the string. I used getline to read a whole line (with spaces too).
Example (what I should get):
User writes: hello
I need to print:…

yak
- 3,770
- 19
- 60
- 111