我有一个包含的c_str [51,53].我想将这些对分成两个整数.它们位于c_str中,因为我从输入文件中读取它们.
必须有一种简单的方法来解析它们.我在考虑使用这个.at功能:但我相信我已经成功了.此外,它不起作用,因为它输出:
pair: 0x7ffffcfc2998
pair: 0x7ffffcfc2998
etc
Run Code Online (Sandbox Code Playgroud)
string pairstring = buffertm.c_str();
stringstream pair1, pair2;
int pairint1, pairint2;
pair1 << pairstring.at(1) << pairstring.at(2);
cout << "pair: " << pair1;
pair1 >> pairint1;
pair2 << pairstring.at(4) << pairstring.at(5);
//cout << "pair: " << pair2;
pair2 >> pairint2;
Run Code Online (Sandbox Code Playgroud)
有更好的方法吗?
这可能是非常基本但是:
作为X与Y同一个类的对象,调用not x == y会导致我的调试器停止类__eq__的方法,但调用x != y不会?
是什么!=检查?它等同于is not(参考检查)吗?
我正在为我的嵌入式C类工作,我遇到了一个我似乎无法解决的问题.我的问题是++i只会改变一次.第一次循环运行i时0,第二次i是1在此之后,无论循环循环多少次,它i都将始终如此1.任何人都知道问题可能是什么?我把它放进printf("%d\n", i);去看是否有i变化.
void addCar() {
char choice = 'y';
int i = 0;
while((choice == 'y' || choice == 'Y') && i < MAX_CAR) {
printf("Make: ");
scanf("%s", fleet[i].make);
getDate(1, i);
getDate(2, i);
printf("Purchaseprice: ");
scanf("%lf", &fleet[i].purchasePrice);
++i;
printf("%d\n", i);
printf("Do you want to add another car? (Y/N)");
scanf("%s", &choice);
}
}
Run Code Online (Sandbox Code Playgroud) 数字和65536是7,因为6 + 5 + 5 + 3 + 6 = 25和2 + 5 = 7我只想为上述任务制作程序.但是当第一次加入10以上时我没有得到正确答案
程序:
#include <stdio.h>
int main()
{
int N, sum = 0, temp;
scanf("%d",&N);
while(1)
{
temp = N%10;
sum += temp;
N = N/10;
if(N==0) {
if(sum>=10) {
N = sum;
}
else {
break;
}
}
}
printf("%d", sum);
return 0;
}
Run Code Online (Sandbox Code Playgroud)