这有点难,我无法弄明白.
我有一个int和一个字符串,我需要将其存储为char*,int必须是十六进制
即
int a = 31;
string str = "a number";
Run Code Online (Sandbox Code Playgroud)
我需要将两个单独的选项卡放入char*中.
输出应该是这样的:
1F a number
Run Code Online (Sandbox Code Playgroud) 这两件事是一样的吗?
for(int i=0; i<array.length; i++){
array[i] = null;
}
Run Code Online (Sandbox Code Playgroud)
和
array = null;
Run Code Online (Sandbox Code Playgroud) 如何覆盖对象类中的equals方法?
即我有
class Person{
//need to override here
public boolean equals (Object obj){
}
Run Code Online (Sandbox Code Playgroud)
我想将参数obj转换为类型Person,但如果我(Person)obj它将无法工作.
我似乎无法弄清楚我的功能有什么问题....我需要询问用户的价格,然后将其作为双指针返回,但我得到了大量的错误:
double* getPrice()
{
double* price;
cout << "Enter Price of CD: " << endl;
cin >> &price;
return price;
}
Run Code Online (Sandbox Code Playgroud) 这是我的问题:
为给定字符串的电话号码创建一个构造函数,其形式为xxx-xxx-xxxx或xxx-xxxx,表示本地号码.如果格式无效,则抛出异常.
所以我想用正则表达式验证它,但我不知道我是否正确地做了.我还要扔什么样的例外?我需要创建自己的例外吗?
public TelephoneNumber(String aString){
if(isPhoneNumberValid(aString)==true){
StringTokenizer tokens = new StringTokenizer("-");
if(tokens.countTokens()==3){
areaCode = Integer.parseInt(tokens.nextToken());
exchangeCode = Integer.parseInt(tokens.nextToken());
number = Integer.parseInt(tokens.nextToken());
}
else if(tokens.countTokens()==2){
exchangeCode = Integer.parseInt(tokens.nextToken());
number = Integer.parseInt(tokens.nextToken());
}
else{
//throw an excemption here
}
}
}
public static boolean isPhoneNumberValid(String phoneNumber){
boolean isValid = false;
//Initialize reg ex for phone number.
String expression = "(\\d{3})(\\[-])(\\d{4})$";
CharSequence inputStr = phoneNumber;
Pattern pattern = Pattern.compile(expression);
Matcher matcher = pattern.matcher(inputStr);
if(matcher.matches()){
isValid = true;
}
return isValid;
}
Run Code Online (Sandbox Code Playgroud)
对不起,是的,这是功课.对于此分配,唯一有效的格式是xxx-xxx-xxxx和xxx-xxxx,在这种情况下,所有其他格式(xxx)xxx-xxxx或xxxxxxxxxx均无效. …
我有个问题.我有以下内容struct:
typedef struct{
int vin;
char* make;
char* model;
int year;
double fee;
}car;
Run Code Online (Sandbox Code Playgroud)
然后我有以下方法询问用户制作汽车并将其作为char指针返回:
char* askMake(){
char* tempMake = NULL;
cout << "Enter Make:" << endl;
cin >> tempMake;
return tempMake;
}
Run Code Online (Sandbox Code Playgroud)
然后我有一辆临时车struct:
car tempCar;
Run Code Online (Sandbox Code Playgroud)
我试图以这种方式为它分配一个值:
tempCar.make = askMake();
Run Code Online (Sandbox Code Playgroud)
它编译得很好,但是我在运行时遇到了分段错误.
嗨,我正在尝试编写一个将播放摩尔斯电码的应用程序.我只是想知道java中是否有默认的系统声音,如是一些嘟嘟声,还是我必须从互联网上下载一些声音文件?
打印int使用时为什么会出现错误的值printf("%f\n", myNumber)?
我不明白为什么它打印好%d,但不是%f.它不应该只是添加额外的零?
int a = 1;
int b = 10;
int c = 100;
int d = 1000;
int e = 10000;
printf("%d %d %d %d %d\n", a, b, c, d, e); //prints fine
printf("%f %f %f %f %f\n", a, b, c, d, e); //prints weird stuff
Run Code Online (Sandbox Code Playgroud) 我来自java背景,我可以用Java做一些我需要用C++做的事,但我不知道该怎么做.
我需要声明一个数组,但此刻我不知道它的大小.一旦我知道了大小,我就设置了数组的大小.我java我会做的事情如下:
int [] array;
Run Code Online (Sandbox Code Playgroud)
然后
array = new int[someSize];
Run Code Online (Sandbox Code Playgroud)
我如何在C++中执行此操作?