getline

c++ getline() looping when used in file with a read in int array?

浪尽此生 提交于 2021-02-11 12:27:46
问题 So I posted this the other day with not enough information and never got an answer once I added the information asked, so I can't get the loop to work so my question is, I am reading from a file that has large text of strings on each line, it then has ints on the next line the strings need to be read into questionArrays() and the ints into answersArrays. Currently the loop simply goes round once and then just loops as it doesn't get any further in the file on the next getline() I did have

Can I use 2 or more delimiters in C++ function getline? [duplicate]

半腔热情 提交于 2021-02-06 15:01:15
问题 This question already has answers here : How can I read and parse CSV files in C++? (37 answers) Closed 2 years ago . I would like to know how can I use 2 or more delimiters in the getline functon, that's my problem: The program reads a text file... each line is goning to be like: New Your, Paris, 100 CityA, CityB, 200 I am using getline(file, line), but I got the whole line, when I want to to get CityA, then CityB and then the number; and if I use ',' delimiter, I won't know when is the next

cin.getline( ) with larger size

谁说我不能喝 提交于 2021-02-04 12:42:46
问题 #include<iostream> using namespace std; int main() { char test[10]; char cont[10]; cin.getline(test,10); cin.getline(cont,10); cout<<test<<" is not "<<cont<<endl; return 0; } When I input: 12345678901234567890 output is: 123456789 It seems cont is empty. Could someone explain it? 回答1: istream::getline sets the fail bit if the input is too long, and that prevents further input. Change your code to: #include<iostream> using namespace std; int main() { char test[10]; char cont[10]; cin.getline

Skip whitespaces with getline

喜你入骨 提交于 2020-12-28 07:50:28
问题 I'm making a program to make question forms. The questions are saved to a file, and I want to read them and store them in memory (I use a vector for this). My questions have the form: 1 TEXT What is your name? 2 CHOICE Are you ready for these questions? Yes No My problem is, when I'm reading these questions from the file, I read a line, using getline, then I turn it into a stringstream, read the number and type of question, and then use getline again, on the stringstream this time, to read

Why is getline() in C++ not working? (no matching function for call to 'getline(std::ofstream&, std::string&)'

徘徊边缘 提交于 2020-08-26 07:16:41
问题 I'm trying to read from a file, but C++ is not wanting to run getline() . I get this error: C:\main.cpp:18: error: no matching function for call to 'getline(std::ofstream&, std::string&)' std::getline (file,line); ^ This is the code: #include <iostream> #include <stdio.h> #include <stdlib.h> #include <fstream> #include <string> using namespace std; int main(){ string line; std::ofstream file; file.open("test.txt"); if (file.is_open()) { while ( file.good() ) { getline (file,line); cout <<

Why is getline() in C++ not working? (no matching function for call to 'getline(std::ofstream&, std::string&)'

人盡茶涼 提交于 2020-08-26 07:15:42
问题 I'm trying to read from a file, but C++ is not wanting to run getline() . I get this error: C:\main.cpp:18: error: no matching function for call to 'getline(std::ofstream&, std::string&)' std::getline (file,line); ^ This is the code: #include <iostream> #include <stdio.h> #include <stdlib.h> #include <fstream> #include <string> using namespace std; int main(){ string line; std::ofstream file; file.open("test.txt"); if (file.is_open()) { while ( file.good() ) { getline (file,line); cout <<