iostream

Program is skipping over Getline() without taking user input [duplicate]

情到浓时终转凉″ 提交于 2020-01-20 07:04:12
问题 This question already has answers here : Why does std::getline() skip input after a formatted extraction? (3 answers) Closed 5 years ago . This is a very strange problem, when my program asks the user for the address, instead of waiting for input, it seems to skip the getline() function completely Answerinput: cout << "would you like to add another entry to the archive? (Y/N):"; cin >> answer; cout << endl; cout << endl; answer = toupper(answer); switch(answer) { case 'Y': Entrynumber++; cout

Program is skipping over Getline() without taking user input [duplicate]

六眼飞鱼酱① 提交于 2020-01-20 07:01:10
问题 This question already has answers here : Why does std::getline() skip input after a formatted extraction? (3 answers) Closed 5 years ago . This is a very strange problem, when my program asks the user for the address, instead of waiting for input, it seems to skip the getline() function completely Answerinput: cout << "would you like to add another entry to the archive? (Y/N):"; cin >> answer; cout << endl; cout << endl; answer = toupper(answer); switch(answer) { case 'Y': Entrynumber++; cout

ios_base::sync_with_stdio(false) does not work between two inputs from stdin

喜欢而已 提交于 2020-01-17 05:23:27
问题 I am wondering why does the following code not work as expected: #include <iostream> #include <string> using namespace std; int main(){ int n; string s; //scanf("%d",&n); cin >> n; ios_base::sync_with_stdio(false); cin >> s; cout << n << " " << s; return 0; } Input: 10 abcd Output: 10 The string is not getting printed! The result is same if I use scanf to input the integer. However, the code does work as expected if the line ios_base::sync_with_stdio(false); is placed before the first cin (or

GCC 4.8 and char16_t streams - bug?

痞子三分冷 提交于 2020-01-16 05:28:12
问题 Is this a libstdc++ bug? #include <string> #include <sstream> using namespace std; int main() { basic_string<char16_t> str(u"0.0"); basic_stringstream<char16_t> sstr(str); double x = 9; sstr >> x; } Output, under GCC 4.8 Linux x86_64: $ ./main terminate called after throwing an instance of 'std::bad_cast' what(): std::bad_cast Aborted (core dumped) Edit Can someone suggest a way to make this function work under GCC 4.9 without changing its signature: template<typename T> T fromString(std:

Using std::copy - error C2679: can't find correct binary '=' operator

不问归期 提交于 2020-01-15 10:43:09
问题 I am trying to use a solution from this question: How do I iterate over cin line by line in C++? The error message c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2144): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const Line' (or there is no acceptable conversion) (and a bunch of template trace data after this) I am using Visual C++ 2010 Express. The code #include<string> #include<iostream> #include<fstream> #include<vector>

Using std::copy - error C2679: can't find correct binary '=' operator

[亡魂溺海] 提交于 2020-01-15 10:42:58
问题 I am trying to use a solution from this question: How do I iterate over cin line by line in C++? The error message c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2144): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const Line' (or there is no acceptable conversion) (and a bunch of template trace data after this) I am using Visual C++ 2010 Express. The code #include<string> #include<iostream> #include<fstream> #include<vector>

Using std::copy - error C2679: can't find correct binary '=' operator

寵の児 提交于 2020-01-15 10:42:11
问题 I am trying to use a solution from this question: How do I iterate over cin line by line in C++? The error message c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2144): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const Line' (or there is no acceptable conversion) (and a bunch of template trace data after this) I am using Visual C++ 2010 Express. The code #include<string> #include<iostream> #include<fstream> #include<vector>

Reading from an iostream

最后都变了- 提交于 2020-01-15 03:34:06
问题 Maybe I'm missing something but I'm having a lot of trouble finding any information on how to how to read from an iostream (std::iostream& stream) . Is there anyway I can convert it to a string or similar? For clarification this is (what I'm basically trying to do, for example): std::stringstream ss("Maybe I'm missing something \n but I'm having a lot of trouble finding any information on how to how to read from an iostream."); readStream(ss); void readStream(std::iostream& stream) { std:

Custom flush implementation

↘锁芯ラ 提交于 2020-01-14 10:09:22
问题 I'm trying to follow the logic of this question to create a custom streambuf in Rcpp. Someone contributed the basic behaviour that allows us to write things like Rcout << "some text" ; where we implemented xsputn and overflow to redirect to Rprintf function. std::streamsize Rcpp::Rstreambuf::xsputn(const char *s, std::streamsize num ) { Rprintf( "%.*s", num, s ); return num; } int Rcpp::Rstreambuf::overflow(int c ) { if (c != EOF) { Rprintf( "%.1s", &c ); } return c; } I would like to

Custom flush implementation

霸气de小男生 提交于 2020-01-14 10:07:43
问题 I'm trying to follow the logic of this question to create a custom streambuf in Rcpp. Someone contributed the basic behaviour that allows us to write things like Rcout << "some text" ; where we implemented xsputn and overflow to redirect to Rprintf function. std::streamsize Rcpp::Rstreambuf::xsputn(const char *s, std::streamsize num ) { Rprintf( "%.*s", num, s ); return num; } int Rcpp::Rstreambuf::overflow(int c ) { if (c != EOF) { Rprintf( "%.1s", &c ); } return c; } I would like to