iostream

How to read float with scientific notation from file C++?

一世执手 提交于 2019-12-05 20:50:10
I have a file with this format: -0.0064785667 0.73900002 0.028505694 4.7858757e-39 315 218 -0.0051828534 0.73900002 0.028505694 4.6936954e-39 316 218 -0.0038818798 0.73799998 0.028467119 5.1546736e-39 317 218 -0.0025879198 0.73799998 0.028467119 5.6160217e-39 318 218 -0.0012939599 0.73799998 0.028467119 6.4461411e-39 319 218 I read it with this code: using namespace std; ifstream inputFile; //Opens data file for reading. inputFile.open(filePath.c_str()); //Creates vector, initially with 0 points. vector<Point> data(0); float temp_x,temp_y,temp_z,rgb=0,discard_1=0,discard_2=0; //Read contents

fatal error C1083: Cannot open include file: 'iostream': No such file or directory

别说谁变了你拦得住时间么 提交于 2019-12-05 17:03:49
I've reinstalled Visual Studio 2010 Professional several times to try to get it to work. I had to uninstall Visual Studio 2012 Professional because it wasn't compiling something we did in class. I completely uninstalled everything including SQL Server.. I went to VC/include and the iostream header file is not there. #include <iostream> int main () { cout << "hello"; system ("PAUSE"); return 0; } This is all I'm trying to do because nothing else is working. It's really driving me crazy because I need to get it working so that I can do my project!!! Every time I do; new project => empty project

Correctly pad negative integers with zeros with std::cout

亡梦爱人 提交于 2019-12-05 14:03:10
问题 I found this question already asked, but the answer everybody gives is std::cout << std::setw(5) << std::setfill('0') << value << std::endl; which is fine for positive numbers, but with -5, it prints: 000-5 Is there a way to make it print -0005 or to force cout to always print at least 5 digits (which would result in -00005) as we can do with printf? 回答1: std::cout << std::setw(5) << std::setfill('0') << std::internal << -5 << '\n'; // ^^^^^^^^ Output: -0005 std::internal Edit: For those

c++ console screen size

倾然丶 夕夏残阳落幕 提交于 2019-12-05 12:59:16
So I'm learning some stuff in College on C++, and the teacher and I got into a discussion on how to actually center text to the output screen. So my suggestion was to use setw but get the length of the string and the size of the console screen, do the algorithm and BAM we have truly centered text. He says the screen size is 80 but the screen can be resized, which doesn't work no matter what if the output is centered the the user starts resizing. Just a minor question I have, how to get the actual size of the console screen? #include <iostream> #include <string> using namespace std; const int

How to derive from C++ std::basic_ostream and make the << operator virtual?

北战南征 提交于 2019-12-05 10:16:24
I am writing a class that has various messages output. I want to make this class general and platform independent, so I am thinking of passing a basic_ostream reference to it and it can dump all the messages into the stream. By doing this, if the class is used in a console program, I can pass std::cout to it and display in console window. Or I could pass a derived ostream to it and redirect the message to some UI components, e.g. ListBox? The only problem is the data inserter operator << is not a virtual function. If I pass the derived class reference to it, only the basic_ostream << operator

What is the best way to make the output of one stream the input to another

烈酒焚心 提交于 2019-12-05 09:39:56
I'm wondering if there is a better/inbuilt way, other than using a byte buffer and looping, to read from one stream and write it to another (in .NET). Generally this is done to apply a transform to a stream and move it on. In this instance, what I am loading a file, putting it through a deflate stream and writing it out to a file (Error handling removed for simplicity): byte[] buffer = new byte[10000000]; using (FileStream fsin = new FileStream(filename, FileMode.Open)) { using (FileStream fsout = new FileStream(zipfilename, FileMode.CreateNew)) { using (DeflateStream ds = new DeflateStream

How to read a file line by line to a string type variable?

孤街醉人 提交于 2019-12-05 09:22:53
I'm trying to read a file line by line to a string type variable using the following code: #include <iostream> #include <fstream> ifstream file(file_name); if (!file) { cout << "unable to open file"; exit(1); } string line; while (!file.eof()) { file.getline(line,256); cout<<line; } file.close(); it won't compile when I try to use String class, only when I use char file[256] instead. how can I get line by line into a string class? Use std::getline : std::string s; while (std::getline(file, s)) { // ... } 来源: https://stackoverflow.com/questions/2581761/how-to-read-a-file-line-by-line-to-a

STL, iostream, new, delete in C/C++ for CUDA

假如想象 提交于 2019-12-05 09:14:41
Can I use STL,iostream,new, delete in C/C++ for CUDA? If you have a Fermi class GPU (so compute capability >=2.0), and are using CUDA 4.0 or later, then both new and delete are avialable for use in device code. STL containers and algorithms and iostream are not supported. If you want to use "STL like" operations with CUDA, you might be interested in the Thrust template library. It allows host code to transparently interact with the GPU using container types and implements a number of very useful data parallel primitives, like sorting, reduction, and scan. Note that this is still a host side

Extending C++ ostream

℡╲_俬逩灬. 提交于 2019-12-05 08:26:47
I'm trying to learn more about the workings of the C++ I/O stream library by extending std::streambuf . As a learning experiment, my goal is to simply create a custom stream which directs all output to std::cerr . It seems simple enough: #include <iostream> using namespace std; class my_ostreambuf : public std::streambuf { public: protected: std::streamsize xsputn(const char * s, std::streamsize n) { std::cerr << "Redirecting to cerr: " << s << std::endl; return n; } }; int main() { my_ostreambuf buf; std::ostream os(&buf); os << "TEST"; } This seems to work, since it prints Redirecting to

Getting a byte value using stringstream

允我心安 提交于 2019-12-05 08:12:09
I've got this (incorrect) sample code for getting a value out of stringstream and storing it in a byte-sized variable (it needs to be in a single byte var, not an int): #include <iostream> #include <sstream> using namespace std; int main(int argc, char** argv) { stringstream ss( "1" ); unsigned char c; ss >> c; cout << (int) c << endl; } The output when I run this is 49, which is not what I would like to see. Obviously, this is being treated as a char and not simple numeric value. What is the most c++ish way to get c to hold a 1 rather than a 49 when casted to an int? Thanks! The most C++-ish