std

Outputting 'wchar_t*' to an 'ofstream'

孤人 提交于 2020-01-29 06:02:25
问题 I want to output a text to a file via two pointers that I have declared: wchar_t *Col1="dsffsd", *Col2="sdfsf"; Here is what I have tried: std::ofstream fout; fout.open(NativeDatabasePathHist); fout<<"testing"; fout<<" "<<Col1<<" "<<Col2; fout.close(); And here is what I am getting: testing 113 113 Why is it that when I print Col1 and Col2 , I am getting numbers instead of strings? 回答1: First, use std::wofstream instead of std::ofstream . Also, use the L prefix on your text string to indicate

Outputting 'wchar_t*' to an 'ofstream'

空扰寡人 提交于 2020-01-29 06:01:25
问题 I want to output a text to a file via two pointers that I have declared: wchar_t *Col1="dsffsd", *Col2="sdfsf"; Here is what I have tried: std::ofstream fout; fout.open(NativeDatabasePathHist); fout<<"testing"; fout<<" "<<Col1<<" "<<Col2; fout.close(); And here is what I am getting: testing 113 113 Why is it that when I print Col1 and Col2 , I am getting numbers instead of strings? 回答1: First, use std::wofstream instead of std::ofstream . Also, use the L prefix on your text string to indicate

C++ - Using istream_iterator with wstringstream

狂风中的少年 提交于 2020-01-23 06:14:20
问题 I am trying to add Unicode support to a program that I wrote. My ASCII code compiled and had the following lines: std::stringstream stream("abc"); std::istream_iterator<std::string> it(stream); I converted this to: std::wstringstream stream(L"abc"); std::istream_iterator<std::wstring> it(stream); I get the following error in the istream_iterator constructor: error C2664: 'void std::vector<_Ty>::push_back(std::basic_string<_Elem,_Traits,_Alloc> &&)' : cannot convert parameter 1 from 'std:

Visual C++ 2010 refuses to show std::string value when debugging. Shows <Bad Ptr>

情到浓时终转凉″ 提交于 2020-01-23 05:58:03
问题 I have a strange feeling like this is a recent issue and happens on two separate computers. When I'm debugging and trying to look at the value of an std::string from STL, it shows as the value. It says its size is 15 and capacity is some garbled huge number. The array values themselves all say CXX0030: Error: expressions cannot be evaluated. This is extremely frustrating and I can still access the string values while debugging if I call c_str on the string and assign it to a char * or use

How do I write binary data for 7z archive format?

拟墨画扇 提交于 2020-01-23 01:50:08
问题 I've been pouring over the format description and source code for the 7z archive format, but I'm still having trouble writing a valid container. I assume I can create an empty container... anyway here's my start: std::ofstream ofs(archivename.c_str(), std::ios::binary|std::ios::trunc); Byte signature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; Byte major = 0; Byte minor = 3; ofs.write((const char*)signature, 6); ofs.write((const char*)major, 1); ofs.write((const char*)minor, 1); UInt64 offset =

Setting a std::function variable to refer to the std::sin function

こ雲淡風輕ζ 提交于 2020-01-22 19:38:29
问题 I've got a question about how to properly use the new C++11 std::function variable. I've seen several examples from searching the Internet, but they don't seem to cover the usage case I'm considering. Take this minimum example, where the function fdiff is an implementation of the finite forward differencing algorithm defined in numerical.hxx (which isn't the problem, I just wanted to give a contextual reason why I'd want to take an arbitrary function and pass it around). #include <functional>

Rust “use” vs. C++ “using namespace”

不打扰是莪最后的温柔 提交于 2020-01-22 18:33:14
问题 Is it considered bad style to declare multiple "use" statements in Rust? I am a C++ programmer that recently began trying out Rust. One thing I've noticed as I review Rust code is that in many Rust programs there will be a bunch of use statements at the top of the program. Coming from C++, it was discouraged to use using namespace std especially when making header files, but that doesn't seem to be the case in most of the Rust programs I've seen. So which of the following trivial examples is

std::regex, to match begin/end of string

∥☆過路亽.° 提交于 2020-01-22 13:44:26
问题 In JS regular expressions symbols ^ and $ designate start and end of the string . And only with /m modifier (multiline mode) they match start and end of line - position before and after CR/LF. But in std::regex/ECMAscript mode symbols ^ and $ match start and end of line always. Is there any way in std::regex to define start and end of the string match points? In other words: to support JavaScript multiline mode ... 回答1: By default, ECMAscript mode already treats ^ as both beginning-of-input

std::regex, to match begin/end of string

江枫思渺然 提交于 2020-01-22 13:42:51
问题 In JS regular expressions symbols ^ and $ designate start and end of the string . And only with /m modifier (multiline mode) they match start and end of line - position before and after CR/LF. But in std::regex/ECMAscript mode symbols ^ and $ match start and end of line always. Is there any way in std::regex to define start and end of the string match points? In other words: to support JavaScript multiline mode ... 回答1: By default, ECMAscript mode already treats ^ as both beginning-of-input

Splitting up lines into ints

空扰寡人 提交于 2020-01-17 07:38:10
问题 I have a file that I read from, it contains a bunch of lines each with a different number of integers, I'm having trouble splitting it up into a vector of a vector of ints. This is my current code. std::vector<int> read_line() { std::vector<int> ints; int extract_int; while((const char*)std::cin.peek() != "\n" && std::cin.peek() != -1) { std::cin >> extract_int; ints.push_back(extract_int); } return ints; } std::vector<std::vector<int> > read_lines() { freopen("D:\\test.txt", "r", stdin);