我知道如果我们在变量声明中关闭尖括号后不放空格,C++会抛出以下错误.
‘>>’ should be ‘> >’ within a nested template argument list
但是如果我#define在这段代码中使用的话,错误就不会出现.有人可以解释一下吗?
我认为#define只是一个宏扩展并且像find-replace一样工作,所以在这里声明变量的方式应该是相同的.
如果我用C++ 11编译它也不会发生此错误.
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
int main(){
//Doesn't work, compile error
vector<vector<int>> v;
//Works
vector<vi> vv;
}
Run Code Online (Sandbox Code Playgroud) 我是新来的github的网页,所以我用一个简单的index.html做了如下回购 https://github.com/jigneshjain25/jignesh.github.com/blob/gh-pages/index.html
但是http://jignesh.github.com/只显示"Hello World".为什么不使用我的index.html文件?
我想建立节点的优先级队列,其中节点的优先级是它们的频率.但是输出不包含正确位置的第一个元素,其余都在正确的位置.
import java.util.*;
class node implements Comparable<node>{
char key;
int freq;
node(){}
node(char k,int f){
key=k;
freq=f;
}
public int compareTo(node n){
if(freq>n.freq)return 1;
return 0;
}
}
public class test{
public static void main(String[] args){
node x=new node('x',4);
node a=new node('a',2);
node b=new node('b',1);
node c=new node('c',7);
PriorityQueue<node> q = new PriorityQueue<node>();
q.offer(a);
q.offer(b);
q.offer(c);
q.offer(x);
while(!q.isEmpty()){
node d=q.poll();
System.out.println(d.key+" "+d.freq);
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
a 2
b 1
x 4
c 7
Run Code Online (Sandbox Code Playgroud)
不应该订购b,a,x,c谢谢.
可能重复:
如何比较Java中的字符串?
当我运行以下代码为"java XYZ BOY"输出为"无效类型"时,如何?
public class XYZ
{
public static void main(String args[])
{
if(args[0]=="BOY")
System.out.println("He is boy");
else if(args[0]=="Girl")
System.out.println("She is girl");
else
System.out.println("Invalid type");
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用时args[0].equals("BOY"),它会提供所需的输出.当我不使用时,我想知道为什么出现问题String.equals()?