如何在c ++中读取空文件?
我用什么循环条件来读取空文件?
因为!fin.eof()条件不起作用并产生无限循环.
我使用turbo c ++,我有2个文件.音乐库文件已有一些专辑.我需要过滤掉并删除重复的相册并将其添加到filterfile中.
我的代码如下:
void albumfilter()
{
song s;
album a;
ifstream fin;
fstream finout;
fin.open("Musiclibrary.txt", ios::binary);
while(!fin.eof())
{
fin.read((char*)&s,sizeof(s));
if(fin.eof())
break;
finout.open("Filteralbum.txt", ios::binary| ios::in| ios::out);
while(!finout.eof())
{
finout.read((char*)&a, sizeof(a));
if(strcmp(a.getfilter_albumname(), s.getalbum())!=0)
{
strcpy(a.getfilter_albumname(),s.getalbum());
finout.write((char*)&a, sizeof(a));
finout.close();
}
}
}
fin.close();
}
Run Code Online (Sandbox Code Playgroud)
这段代码是否正确?
我正在为MMORPG和管理员后端设计数据库.我需要一个允许我添加指定数量的游戏主要货币的功能:Gold到数据库中的每个帐户.
这就是我所拥有的:
function massAddGold($gold_amount){
dbconnect();
$value=mysql_query("SELECT * from `mmo_db1`.`users`;");
while ($row=mysql_fetch_array($value)){
$currentgold=$row['gold'];
$newgold=$currentgold+$gold_amount;
mysql_query("UPDATE `mmo_db1`.`users` SET `gold` = \"$newgold\";");
}
dbclose();
}
Run Code Online (Sandbox Code Playgroud)
where mmo_db1是数据库的名称.
当我执行命令时,massAddGold("50");我然后检查数据库.它采用具有最高值的行Gold,将其添加50 gold到该行,然后将该值应用于所有行.我需要它分别在每一行上执行.
我不知道如何保持这个简单......我希望有人看看我的代码然后告诉我为什么我的功能不能正常工作......
我有一节课:
class PriorityQueue(object):
'''A class that contains several methods dealing with queues.'''
def __init__(self):
'''The default constructor for the PriorityQueue class, an empty list.'''
self.q = []
def insert(self, number):
'''Inserts a number into the queue, and then sorts the queue to ensure that the number is in the proper position in the queue.'''
self.q.append(number)
self.q.sort()
def minimum(self):
'''Returns the minimum number currently in the queue.'''
return min(self.q)
def removeMin(self):
'''Removes and returns the minimum number from the queue.''' …Run Code Online (Sandbox Code Playgroud) 有人可以向我解释为什么这不起作用?
对不起,我是javascript + jQuery的首发.
这是代码:
Javascript/jQuery:
<script type="text/javascript">
$('.clickk').click(function(e){
window.location.href = $(this).find('a').attr('href');
});
</script>
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="clickk" >
<a href="google.com">link</a>
blah blah blah.
</div>
Run Code Online (Sandbox Code Playgroud)
请帮我找到我失踪的东西.
提前致谢.希望问题很清楚.
我的问题是,cin如果发生错误,我无法重置流.例如,如果我在需要int时输入一个字符串,然后我清除了流,那么当循环到下一次时,我仍然会到达cin.fail()-if.
有帮助吗?
我的代码如下:
int main()
{
int i;
while(cin>>i,!cin.eof())
{
if(cin.fail())
{
cin.clear();
continue;
}
cout<<i<<endl;
}
system("pause");
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句:有关信息,我使用Visual Studio作为IDE.
我有一个jQuery点击事件的简单问题,我无法解决.
这是代码:
$('document').ready(function() {
var links = $('.brandLinks li a');
console.log(links.length); // there are total 24 items are there
for(var i = 0; i < links.length; i++) {
links[i].click(function(e){
console.log('click.');
});
}
});
Run Code Online (Sandbox Code Playgroud) 我有df=[4,5,6]和df2=[7,8,9],因为两个指数都是0,1,2。
我用过pd.concat([df,df1]),但结果给了我指数0,1,2,0,1,2。
我想要结果 df 指数 0,1,2,3,4,5
有什么帮助吗?
当我调用我的calculatePlaneEQ函数时,当我分配值时,它会抛出一个访问冲突...我的指针生锈了,但似乎这应该有效!
float *planeCoefA, *planeCoefB, *planeCoefC, *planeCoefD = NULL;
Run Code Online (Sandbox Code Playgroud)
呼叫:
calculatePlaneEQ (<...>, &planeCoefA, &planeCoefB, &planeCoefC, &planeCoefD);
Run Code Online (Sandbox Code Playgroud)
DEF:
void calculatePlaneEQ (<...>, float ** myXnorm, float ** myYnorm, float ** myZnorm, float** myD)
{
float xNorm = 1.3;
float yNorm = 1.4;
float zNorm = 1.5;
float eqD = 1.6;
*(*myXnorm) = xNorm;
*(*myYnorm) = yNorm;
*(*myZnorm) = zNorm;
*(*myD) = eqD;
}
Run Code Online (Sandbox Code Playgroud)