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

Can't use getline when reading from a file

I want to read numbers from a file and I'm having problems with the getline. I have the following code, I'll post the part that matters: main.cpp int main() { GrafNoEtiquetat Graf; ifstream f_ent; ofstream f_sort; string str; …
p. bosch
  • 139
  • 2
  • 10
0
votes
2 answers

Extract an specific count of chars with cin.get and make sure is correct

I want to extract 6 chars (including '\n') from input to an array and ensure that the input is correct by getting the new line character at an specific place in the array. This is what I did but I cant fix it. If the user enters more than 5…
0
votes
2 answers

Segmentation fault with getline in C++

I'm working on an assignment for my programming class. One of the given function prototypes is: string read_text(const string & prompt); I wrote the function definition as: string read_text(const string & prompt) { cout << "Enter your text: "; …
user3010573
  • 13
  • 1
  • 2
0
votes
2 answers

Code to get user input not executing/skipping in C++

In the below code, I'm running into an error when I try to get the user to input their name. My program just skips it over and goes right over to making the function calls without allowing the user to enter their name. Despite the error, my program…
user2875331
0
votes
1 answer

Using getline to read either just a newline or text

So what I need to do is get input from a user, a filename specifically, with the alternative of the user just pressing enter to default to a certain filename. Here is what I have: cout << "Where should I save the exam (default exam.txt):…
user1111098
  • 287
  • 1
  • 3
  • 4
0
votes
2 answers

Getting line from a txt file using fstream

int main(int argc, const char * argv[]) { ifstream input; input.open("test.txt"); string arrAtoms[700]; string temp; int i = 0; while(getline(input, temp)){ if(startsWithAtom(temp)) { arrAtoms[i] = temp; …
soochism
  • 13
  • 1
  • 5
0
votes
1 answer

Read in Single Quote using getline()

I'm doing UVa Problem 10082 and I'm trying to read in some sample input to test my solution. However, when I read in the text '''CCC it outputs ;;XXX. Note that there are only 2 semi-colons, when there should be 3 since there are 3 single quotes in…
muttley91
  • 12,278
  • 33
  • 106
  • 160
0
votes
2 answers

How to read a file word by word and find the position of each word?

I'm trying to read a file word by word and do some implementation on each word. In future I want to know where was the position of each word. Position is line number and character position in that line. If character position is not available I only…
Bernard
  • 4,240
  • 18
  • 55
  • 88
0
votes
3 answers

operator>> error: no matching function for call to

I'm working with a class Allotjament, that has 5 attributes, 4 of them are from a class called Cadena, which I have finished too, here's is Allotjament.cpp: #include #include #include "Allotjament.h" …
p. bosch
  • 139
  • 2
  • 10
0
votes
1 answer

Getline not storing integer properly

string line; int input; stringstream linestream; cout << "\nEnter integer: "; getline(cin,line); cout << "\nNumber is << line; when…
oomkiller
  • 169
  • 3
  • 11
0
votes
4 answers

strncmp() gives a false positive

I have been expirencing an issue with strncmp and getline... so a i made a little test app. strncmp gives false positives and i can't figure out what i am doing wrong. this is the program #include FILE *fp=NULL; char uname[4]="test"; char…
MrBlarg64
  • 13
  • 1
  • 2
0
votes
2 answers

linecache.getline and how to loop to the next line

I have this code doing a loop file.write('' + linecache.getline('support_files/sub_page_top_links.txt', 1) + '') It gets the first line in the text file, but, the next time the script loops I need it to get line 2, then the next time the script…
0
votes
1 answer

reading global istream* with getline error

I'm trying to read a global istream* using the following code: /*Global Declaration*/ istream* fp; /* in main */ ifstream iFile; if(argc == 2) //open file code fp = &file; else fp = &cin; readFile; /*readFile*/ readFile(){ string line; …
0
votes
1 answer

Reading variable sized columns in a matrix

I have a file that contains different columns in different lines. For example 10 20 30 60 60 20 90 100 40 80 20 50 60 30 90 .... I want to read the last three numbers in each row. So the output will be 20 30 60 100 40 80 60 30 90 I can not use…
mahmood
  • 23,197
  • 49
  • 147
  • 242
0
votes
1 answer

std::out_of_range at memory location error at getline

I'm very new to c++ there is a good bit of code here, so im going to do my best to condense it to the problem area. when I try to get user input using getline im getting this error. Since i don't expect spaces in the file names(i made the files)i…
Bryan
  • 3,449
  • 1
  • 19
  • 23