Created
May 29, 2022 17:56
-
-
Save fowlmouth/3206cc1e6b866e59a173e962163a52ed to your computer and use it in GitHub Desktop.
streams issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
c++ main.cc -o main -std=c++20 && ./main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sstream> | |
#include <iostream> | |
#include <locale> | |
#include <codecvt> | |
template< typename stream > | |
void test(stream&& ss) | |
{ | |
// stream ss("abc"); | |
for(int i = 0; i < 4; ++i) | |
{ | |
std::cout << (int)ss.get() << ' '; | |
} | |
std::cout << std::endl; | |
ss.clear(); | |
ss.seekg(0, ss.beg); | |
for(int i = 0; i < 4; ++i) | |
{ | |
std::cout << (int)ss.get() << ' '; | |
} | |
std::cout << std::endl; | |
} | |
int main() | |
{ | |
test< std::istringstream >(std::istringstream{"abc"}); | |
std::cout << "---" << std::endl; | |
test< std::wistringstream >(std::wistringstream{L"abc"}); | |
std::cout << "---" << std::endl; | |
test< std::wistream >(std::wistringstream{L"abc"}); | |
std::cout << "---" << std::endl; | |
{ | |
std::stringbuf buf; | |
buf.str("abc"); | |
std::wbuffer_convert< std::codecvt_utf8< wchar_t >> conv(&buf); | |
test< std::wistream >(std::wistream(&conv)); | |
} | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 98 99 -1 | |
97 98 99 -1 | |
--- | |
97 98 99 -1 | |
97 98 99 -1 | |
--- | |
97 98 99 -1 | |
97 98 99 -1 | |
--- | |
97 98 99 -1 | |
-1 -1 -1 -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment