我在打印课程时遇到问题。我希望此类读取二进制数,然后打印出来。我是一个初学者,所以这里可能是一个非常愚蠢的错误。 该代码输出错误,但输入正确。 我试图解决此问题,但无法解决。希望您会发现错误。 请帮忙。谢谢!
代码如下:
using (ProductContext db = new ProductContext())
{
log.Info("Checking for expired data in the Product Data db");
//rule = now - configured hours, default = 2 hours in past.
var checkWindow = Convert.ToInt32(PRODUCTMAPPING_CONFIG.MinusExpiredWindowHours);
var dtCheck = Convert.ToDateTime(DateTime.Now.AddHours(-checkWindow).ToString("s"));
// Ammended DB Table from nvarchar to DateTime to allow direct comparison based on comment by: Panagiotis Kanavos
// Removed ToList() which returned the IEnumerable immediately based on comment by: jdweng
var rowData = db.ProductData.Where(le => le.ProductEndDate < dtCheck);
log.Info($"Number of expired Products being removed: {rowData.Count()}");
// added print out on debug only.
if(log.IsDebugEnabled)
rowData.ToList().ForEach(i => {log.Debug($"DB Row ID {i.Id} with Product ID Value: {i.ProductUid} has expired with Product End Date: {i.ProductEndDate}, marked for removal."); });
var rowCount = rowData.Count();
db.ProductData.RemoveRange(rowData);
db.SaveChanges();
log.Info(rowCount == 0
? "No expired data present."
: $"Number of expired assets Successfully removed from database = {rowCount}");
}
答案 0 :(得分:1)
问题出在这行代码上:
out << b.arr;
您正在打印数组指针b.arr
,而不是数组中的值。
这将起作用:
out << b.arr[i] ? '1' : '0';
您还应该考虑编写析构函数以释放先前分配的内存,并在覆盖此行的指针之前释放先前的数组:
b.arr = new bool[b.len];