当此代码运行时,它将获取网页的内容.
我想连接整个字符串而不是将它打印到控制台但是当我在下面的代码中取消注释两行时,System.out.println(inputLine);
什么都不打印(但是它与下面注释的行一起使用)和值fileText = null
,
这个错误来自哪里?
import java.net.*;
import java.io.*;
public class URLReader {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://www.oracle.com");
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String fileText = "";
String inputLine;
while ((inputLine = in.readLine()) != null)
//fileText.concat(inputLine);
System.out.println(inputLine);
in.close();
//System.out.println(fileText);
}
}
Run Code Online (Sandbox Code Playgroud) 我想在d3中创建几个按钮.为了有一个更清晰的代码我想在数组中添加他们的名字.
我有以下代码,但它不起作用:
var buttonNames = ["button 1", "button 2", "button 3", "button 4"]
d3.select("body").selectAll("input").data(buttonNames).enter().append("input").attr("type","button").attr("class","button").attr("value", function d(){return d;} )
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的回复.
我正在尝试在c ++中实现后缀树,同时将节点添加到向量列表中,在向树中添加第三个元素后,它会引发std :: bad_alloc。我不知道为什么它在第三次之后发生,您能帮我解决这个bad_alloc错误吗?
这是我的代码:
suffix_tree.cpp
#include <iostream>
#include <fstream>
#include <cmath>
#include <sstream>
#include <string>
#include <cstring>
#include "node.h"
using namespace std;
Node build_suffix_tree(string text){
Node root = Node();
int n = text.length();
int count;
Node * currentNode = &root;
Node tmpNode;
string suffix;
int suffixLen;
for(int i=0; i<n; i++){
suffix = text.substr(i,n);
suffixLen = suffix.length();
count = 1;
currentNode = &root;
while(count <= suffixLen){
cout << suffix << endl;
int pos = -1;
// bad_alloc occurs here
(*currentNode).addFils(Node(suffix[0], …
Run Code Online (Sandbox Code Playgroud)