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
2 answers

getline delimiter using stringstream

It seems that it's not separating the word within the space. Trying to separate the words in between, and stored it in first and second. cin >> name; //input name stringstream file (name); getline(file,first, ' '); //seperate the name with the…
user1745860
  • 207
  • 1
  • 5
  • 11
0
votes
2 answers

Reading Lines from File and Storing in Separate String Variables

I am creating a bank terminal for an assignment. It has the ability to add clients with each client containing 5 different variables for name, address, social#, employer, and income. Those variables are then written to a file once they have been…
user1710357
  • 3
  • 1
  • 7
0
votes
3 answers

Assigning file data to array of structs

I'm currently attempting to assign a line of data from an input file to an array of structs. Here is my struct: struct student { int ID; int hours; float GPA; }; student sStudents[MAX_STUDENTS]; // MAX_STUDENTS =…
user2309237
0
votes
1 answer

Escaping from loop for line in file but still get the rest of the file as string

The following code gets each line from a txt file. If the line is "References\n" the file should continue to getlines, but appended to another string removing the subsequent '\n' instances. How should I deal with the nested loops and breaks? for…
raw-bin hood
  • 5,839
  • 6
  • 31
  • 45
0
votes
0 answers

getline() doesn't end long input

I need to input in my program a big string until the user types a delim char and I've written this code: int main(int argc, const char * argv[]) { string str, temp; string c; cout << "Insert delim char:" << endl; getline(cin,…
fpiro07
  • 847
  • 1
  • 13
  • 18
0
votes
2 answers

Every other line of data is skipped when reading and storing data from a file

I'm new to C++ and I'm having a little trouble when it comes to reading lines of data from a text file. Let's say I have an unknown number of lines in a text file, with each line in the same format: int string double . The only thing that will be…
Dawg Pwnd
  • 1
  • 1
0
votes
3 answers

How to prevent "\n" being written at the end of file

I am writing a program to read/write from a text file which contain employee information. Each employee information is stored inside a textfile like below. Employee information is stored to four lines. W00051 M Christopher Tan 1200.00 150.00 1400.20…
Axel
  • 1,053
  • 9
  • 19
0
votes
3 answers

Beginner Error with "getline"

this is my first time posting a question so I hope I'm getting this right. Anyways, I'm trying to create a program to ask the user for a string, count the types and numbers of letters, then output the frequency of the letters. So far I'm having an…
user2250690
  • 35
  • 1
  • 5
0
votes
1 answer

Linecache adding an extra line to the line that i get

When i try to get a line using linecache in python. loginpass = raw_input("> ") if loginpass == linecache.getline('Password.txt', 1): The line that it gets always returns with an extra line. So if line one is "Test" It returns "Test " It worked…
0
votes
1 answer

Finding a match to a string with getline

I am trying to search a vector of string names for matches. Names can be more than one word so in prompting the user I am using getline(std::cin, name); however I can never find matches with the existing names in the vector. How do I remove the…
0
votes
3 answers

Issue reading space from file

I am trying to read a line from a file that has spaces in it. Despite everything I've tried and all my research, nothing seems to work, here is my current attemp void read_name(fstream& in_file, comp& cmp) { char buff[80]; …
roundtheworld
  • 2,651
  • 4
  • 32
  • 51
0
votes
1 answer

C++ getline() jumped over empty strings

I'm reading with my c++ program csv file: abc;def;ghi 10;;10 by this code: while(getline(in, str, '\n')){ stringstream ss; while(getline(ss, str, ';')){ line.add(str); } } Where in is input file, str is string…
0
votes
0 answers

std::getline returning the wrong size

something wrong with getline(), taking the words in correct but still the value of size remains 26. I tried printing each time it takes in a character and all of them do print so itis taking in strings correctly, but not storing them? I have…
Chinmay
  • 13
  • 1
  • 3
0
votes
1 answer

C++ getline() restarting before reading entire file

The gist of my problem is that I am reading a file with fields separated by #'s except for the end of the line. When I look at the print statements for the fields that I am reading into a book struct (that uses a for loop to go through the entire…
user963070
  • 629
  • 2
  • 19
  • 24
0
votes
1 answer

Continuously input lines using getline to end of txt document C++

I have a really long .txt file which I want to stream in using getline. I want to input this entire text document, and then run it through a procedure. I then want to run that new string through the same procedure using a different values, and so on…
1 2 3
99
100