[英]C++ iostream encoding?
I have an input.txt
and an output.txt
, obviously I generate the output.txt
, which for now is to write the exact same thing out, but it does not do that because of a possible encoding(?) error.我有一个
input.txt
和一个output.txt
,显然我生成了output.txt
,现在是写出完全相同的东西,但由于可能的编码(?)错误,它没有这样做。
Here are pictures of the input and output:以下是输入和 output 的图片:
My code looks like this:我的代码如下所示:
Menu.cpp:菜单.cpp:
void Menu::kiir(){
ofstream myfile("output.txt");
if (myfile.is_open()){
myfile << sakk.toString();
}
}
The toString()
method in sakktabla.cpp
: sakktabla.cpp
中的toString()
方法:
string sakktabla::toString(){
std::string eredmeny="";
int x = this->x;
int y = this->y;
for (int i = 0; i < x; i++){
for (int j = 0; j < y; j++){
eredmeny += (int)getValue(i, j);
}
eredmeny += "\n";
}
return eredmeny;
}
The getValue()
method: getValue()
方法:
int sakktabla::getValue(int x, int y){
return this->_vec[x][y];
}
I don't see where you're ingesting, but you seem to be:我没有看到你在哪里摄取,但你似乎是:
'2'
;'2'
;2
;2
;2
.2
的 ASCII 字符。 Possibly the confusion is that std::string::operator+=
doesn't do any sort of conversion.可能令人困惑的是
std::string::operator+=
不进行任何类型的转换。
You possibly want:你可能想要:
eredmeny += std::to_string(getValue(i, j));
std::to_string()
converts a bunch of numeric types to their human-readable string counterparts. std::to_string()
将一堆数字类型转换为人类可读的字符串对应物。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.