iostream

std::cerr can't print float variable

核能气质少年 提交于 2019-12-25 19:53:20
问题 I am writing a program that is supposed to operate with matrices and to use OpenGL framework for drawing them. Honestly, it's just for practice. Anyway, I tried to compile it and, of course, it didn't run well. Inserting as many logging as I could, I found out that my std::cerr can't print float values. I really got no idea how that may stop working. I have made some deep researches on my little code like replacing variables with their values, coding external programs using same functions and

three out of five file streams wont open, i believe its a problem with my ifstreams [closed]

僤鯓⒐⒋嵵緔 提交于 2019-12-25 09:42:11
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . #include<iostream> #include<fstream> #include<cstdlib> #include<iomanip> using namespace std; int main() { ifstream in_stream; // reads itemlist.txt

ofstream(mode ios::out) wipes existing file blank when system halt

徘徊边缘 提交于 2019-12-25 07:47:55
问题 The usage scenario is industrial (unstable power supply and other buggy programs/hardware). It is required that the program should come back unaffected when power is off (or blue-screen crash). OS is Windows 7 with NTFS. I use boost::property_tree write json to record parameters to human readable text file. boost::property_tree::write_json("logic.txt", pt); It actually wiped the "logic.txt" sometimes, when system halt. I read the boost source file and write_json calls ofstream with default

How do you flush the contents of `std::cin` before an additional read from it?

戏子无情 提交于 2019-12-25 04:12:06
问题 I am trying to read a single character multiple times . The catch is that I need to prevent user errors. So for example: char arr[10]; for(int i = 0; i < 10; i++) { cin.get(arr[i]); } Where the inputs should be something like a, b, c, d, ... . But if someone were to enter ab for the first entry I want to capture the a and then ignore the b . I know about cin.ignore however I don't know how I would go about ignoring an arbitrary number of alphanumeric characters or symbols considering that I

Calling IOS::exception(…) causes EOF to throw InteropServices.SEHException from std::getline(…) in C++-CLI, why?

廉价感情. 提交于 2019-12-25 03:55:30
问题 I run the following function to load a file. It is being ported from CLI to standard C++ and exhibits unexpected behaviour when I attempt to specify that I would like to throw all exceptions except EOF. bool parseFile(ManagedClass *%parsedFileAsManagedObject, const string &fileName); std::string line; bool success = true; ifstream is(fileName.c_str()); //Unless I comment out the following line I get problems is.exceptions( ifstream::badbit | ifstream::failbit ); //do stuff try { while

getline(cin, string) not working EVEN WITH cin.ignore()

丶灬走出姿态 提交于 2019-12-25 03:34:17
问题 There are several questions on this site referring to getline not working, the apparent solution is that there are remaining newline characters in the buffer that need to be cleared, supposedly with cin.ignore() . I've tried so many variations of this and nothing seems to work, all I'm trying to do is simple console input and cin >> string isn't an option because the string might have spaces. Here is my code. void prompt(std::string * str) { cout << "> "; cin.sync(); cin.get(); cin.ignore(256

Puzzling behavior of istream::getline()

别等时光非礼了梦想. 提交于 2019-12-24 21:42:40
问题 I tested following codes to clarify my understanding to istream::getline() : #include <iostream> #include <sstream> using namespace std; int main() { string s("abcd efgh\nijklmnopqrst"); string s1; stringstream ss(s); ss >> s1; cout << s1 << endl; ss.getline(&s1[0], 250, '\n'); cout << s1 << endl; ss >> s1; cout << s1 << endl; getchar(); return 1; } then the console printed: abcd efg ijklmnopqrst but in my opinon it should be abcd efgh ijklmnopqrst Besides, I found the size of s1 after

Swapping a stringstream for cout

和自甴很熟 提交于 2019-12-24 16:41:35
问题 With glibc's stdio, I can swap a memstream for stdout, thereby capturing the output of a piece of code compiled to output to stdout: #include <stdio.h> void swapfiles(FILE* f0, FILE* f1){ FILE tmp; tmp = *f0; *f0 = *f1; *f1 = tmp; } void hw_c(){ puts("hello c world"); } int c_capt(){ FILE* my_memstream; char* buf = NULL; size_t bufsiz = 0; if( (my_memstream = open_memstream(&buf, &bufsiz)) == NULL) return 1; FILE * oldstdout = stdout; swapfiles(stdout, my_memstream); hw_c(); swapfiles(stdout,

creating an iostream object in c++

守給你的承諾、 提交于 2019-12-24 11:50:11
问题 I'm going to try asking this again, but better than the last time. I have a program that reads binary data in from various places, and then manipulates it in a class that I have written. The data will be read originally from it's source (which may vary), then get written to a stream, and that stream will be passed into the class for the class to work on. My struggles are with figuring out how to create an iostream and write to/read from it. I have looked in various places and read the

fatal error C1075: end of file found before the left brace and read and write files not working

匆匆过客 提交于 2019-12-24 09:07:23
问题 could someone also tell me if the actions i am attempting to do which are stated in the comments are correct or not. i am new at c++ and i think its correct but i have doubts #include<iostream> #include<fstream> #include<cstdlib> #include<iomanip> using namespace std; int main() { ifstream in_stream; // reads itemlist.txt ofstream out_stream1; // writes in items.txt ifstream in_stream2; // reads pricelist.txt ofstream out_stream3;// writes in plist.txt ifstream in_stream4;// read recipt.txt