stringstream

Displaying data from 2d array and stringstream

こ雲淡風輕ζ 提交于 2019-12-25 03:40:08
问题 I'm writing a program that reads data from a file that looks like: W Z W Y W Y W W Y W Y Z W Z Y Z W W W Y W Y W Z Y W Z W Y Y Z W Z Z Y Z Z W W W Y Y Y Z W Z W Z Z Y Z Z W W W Y Y Y Z W Z W Z Z Y Z Z W W W Y Y Y Z W These characters (W, Y, or Z) are parsed using a stringstream and stored in a 2D array that's 5x15. Now I'm having trouble counting the amount of times that each character appears on each line . I've tried multiple ways of achieving this by using counter variables in my function

Why does TStringStream.Bytes differ from what one gets from 'TStream.Read'

混江龙づ霸主 提交于 2019-12-24 12:34:01
问题 With TStringStream, the bytes using its Bytes property differs from the bytes extracted using TStream.Read . As shown below: the bytes extracted using TStream.Read represents correct data. the bytes using its Bytes property contains more data. (the last byte of correct bytes is different from that of wrong bytes ) Could you help to comment about the possible reason? Thank you very much for your help! PS: Delphi XE, Windows 7. (It seems TStringStream back in Delphi 7 doesn't have LoadFromFile

C++ stringstream inline

不羁的心 提交于 2019-12-23 10:07:41
问题 I would like to use std::stringstream to create formatted strings, but use the class inline so I don't have stringstream local variables flying around. What I mean is this: #include <iostream> #include <ostream> #include <string> #include <sstream> int main(int argc, char* argv[]) { std::string test = ((std::ostringstream&) (std::ostringstream("") << "This is a test: " << 50.1 << "abc") ).str(); std::cout << test << std::endl; return 0; } This compiles fine in GCC, however the output is the

C++:利用stringstream对数字和string互相转换

我只是一个虾纸丫 提交于 2019-12-22 22:49:37
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 需要 #include <sstream> 。 数字转换为string字符串 #include <iostream> #include <sstream> int main() { std::stringstream ss; ss << 100; std::cout << ss << std::endl; std::cout << ss.str() << std::endl; std::cout << ss.str().compare("10") << std::endl; // 比较字符串 std::cout << ss.str().compare("100") << std::endl; std::cout << ss.str().compare("102") << std::endl; std::string data("100"); std::cout << ss.str().compare(data) << std::endl; } 编译运行: $ g++ test.cpp $ ./a.out 0x7ffea3490478 100 1 0 -2 0 ss.str() 是字符串结果。string类型之间比较可以用compare函数,若相等则返回值为0。 注意 ,0在条件判断中代表false,所以必须if

String to float using stringstream

时光总嘲笑我的痴心妄想 提交于 2019-12-22 05:09:30
问题 I found this code online as a template for doing a string to float/int/double conversion. It's only here so I have something to reference for the question.... I want to have a user enter a number as a string, convert it to a float, test it for success and drop out if entry was 'Q' or print "Invalid input" if it wasn't the 'Q'uit character and return for more input. What's the syntax for a conversion fail test? Would it be ss.fail() ? // using stringstream constructors. #include <iostream>

C++ reset locale to “C” globally?

我是研究僧i 提交于 2019-12-22 04:10:51
问题 In a project I am currently working on I link to a proprietary dynamic library. As soon as I run the library's initialize function, the behavior of logging and printing of numbers changes. Commas have been inserted at every third decimal. Ie. cout << 123456789 << endl used to print out 123456789 and now it prints 123,456,789 . This is horribly annoying, because this behavior is not what I want. This issue is not only apparent in the binary I am compiling, but also shows up in all the couts

C++ reset locale to “C” globally?

时间秒杀一切 提交于 2019-12-22 04:10:48
问题 In a project I am currently working on I link to a proprietary dynamic library. As soon as I run the library's initialize function, the behavior of logging and printing of numbers changes. Commas have been inserted at every third decimal. Ie. cout << 123456789 << endl used to print out 123456789 and now it prints 123,456,789 . This is horribly annoying, because this behavior is not what I want. This issue is not only apparent in the binary I am compiling, but also shows up in all the couts

C++: From stringstream to char**

。_饼干妹妹 提交于 2019-12-22 01:43:27
问题 I have a class with parse(int argc, char* argv[]) function which I have to use to set a desired state of an object. I'm taking the parameters from the gui using stringstream and then I'm trying to convert them to char** to pass them to the function. Here's what I've got: std::stringstream sstream; sstream << "-clip" << " " << min_x_entry.get_text() << " " << max_x_entry.get_text(); // etc. std::cout << sstream.str(); // All looks good here std::vector<std::string> args; std::vector<char*>

C++ reading a text file with conditional statements

≯℡__Kan透↙ 提交于 2019-12-21 21:37:12
问题 I am trying to read lines in a text file, tokenize the line and then go on and do the same to the next line in a switch and break block, but after my program reaches the first break, it exits the loop and ignores the rest of the file. ifstream in("test.txt"); string line,buffer; unsigned int firstLetter = 0; //istringstream iss; if( in.is_open() ) { istringstream iss; while(getline(in,line)) { iss.str(line); char firstChar = line.at( firstLetter ); switch ( firstChar ) { case 'D': while

Make varargs Exception constructor to fill stringstream

青春壹個敷衍的年華 提交于 2019-12-21 05:21:16
问题 Basically I am making Exception class and I want to be able to pass debug details easily, such as this: var error = someFunction(); if(error!=0) { throw MyException("someFunction ended with error state #",error,'.'); } This would require the MyException class to accept varargs arguments that can be processed by stringstream . I have no idea how exactly could I do that, what I imagine is this: #include <string> #include <sstream> template /* MUCH DEEP MAGIC HERE**/ MyException::MyException(/*