小编R. *_*des的帖子

Java使用UTF-8读取和写入文件到文件

我正在创建一个类似日语字典的程序,所以我需要将日文单词对象存储在一个文件中.我目前正在尝试创建一个无线编码的dat文件,但我一直在获取FileNotFound Exceptions.我的主要目标是能够将我自定义创建的单词对象存储在一个文件中,该文件可以存储和读取包含日文文本和值数组的对象.所以如果你知道无论如何要解决这个问题,我将非常感激!

这是我的试用课来测试它:

  public class JavaApplication1 {

/**
 * @param args the command line arguments
 */
Scanner scan = new Scanner(System.in);
//File file = new File("test.dat");
public static void main(String[] args) throws FileNotFoundException, IOException,    ClassNotFoundException {
    // TODO code application logic here
    JavaApplication1 ja = new JavaApplication1();
    ja.start();
}
public void start() throws FileNotFoundException, IOException, ClassNotFoundException{

    System.out.println("Enter Kanji");
    String Kanji = scan.next();
    System.out.println("Enter Romanji");
    String Romanji = scan.next();
    System.out.println("How common is it");
    int common = scan.nextInt();
    System.out.println("How many types of …
Run Code Online (Sandbox Code Playgroud)

java filenotfoundexception

1
推荐指数
1
解决办法
1209
查看次数

在移动被认为安全之前得到右值参考的地址?

我正在玩Move Semantics和[r | l]值引用来学习如何在真实世界的程序中使用它们.考虑以下代码:

// Item is a heavy class having move ctor and assignment but no copy. 
std::map<std::string, Item*> lookup;
std::forward_list<Item> items;
void FooClass::addItem(Item&& d) {
    if (lookup.find(d.getName()) == lookup.end()) {
        lookup[d.getName()] = &d;    //<== not safe after move?
        items.push_front(std::move(d));
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在获取一个地址Item&&并将其存储在指针中.然后将数据移动到std::forward_list(items).我假设调用移动赋值不会影响对象的地址.那是对的吗?虽然d移动后内容不再有效.这是查找表(lookup)的内容不正确.

我假设我必须重新订购a)添加查找项目和b)移动实际数据.上面的代码并不理智.它是否正确?

我也不明白为什么我要说std::move那里.编译器应该知道这d是一个右值引用.所以它应该调用std::forward_list<T>::push_front(T&&)并移动赋值...

c++ rvalue-reference move-semantics c++11

1
推荐指数
1
解决办法
1093
查看次数

Haskell类的错误我一直都在下降,无法理解

我遇到了一个错误,但无法理解如何使它正确.给我这个错误的代码示例是:

class Someclass a where
    somefunc :: (Num b) => b -> a -> a

data Sometype = Somecons Int

instance Someclass Sometype where
    somefunc x (Somecons y) = Somecons (x+y)
Run Code Online (Sandbox Code Playgroud)

错误消息是:

无法将预期类型'b'与推断类型'Int'匹配''
'b'是一个严格的类型变量,由error.hs中的'somefunc'的类型签名绑定:3:21
在'(+)'的第二个参数中,即'y'
在'Somecons'的第一个参数中,即'(x + y)'
在表达式中:Somecons(x + y)

据我所知,错误消息试图告诉我,我使用的是Int类型的名称,他期望类型为(Num b)=> b.我无法理解的是Int适合(Num b)=> b.难道编译器不应该理解我告诉他的内容(对于这个特定的实例,b应该是一个整数吗?我怎样才能使它合适?

Coment:当然在这个具体的例子中,我可以使用类型签名制作somefunc:

somefunc :: a -> a-> a 
Run Code Online (Sandbox Code Playgroud)

但是我希望我想要这样的东西:

data Newtype = Newcons (Int, Int) 

instance Someclass Newtype where
    somefunc x (Newtype (y,z) ) = Newtype (y+x, z)
Run Code Online (Sandbox Code Playgroud)

当我试图在哈斯克尔做某事时,反复发生这样的事情.

haskell type-systems class

0
推荐指数
2
解决办法
244
查看次数

任何人都可以在C#界面中使用静态方法吗?

我想实现一个集合,其项目需要进行空虚测试.在引用类型的情况下,将测试为null.对于值类型,必须实现空测试,并且可能选择表示空白的特定值.

我的T的一般集合应该是两个值和参考类型值可用(意味着Coll<MyCalss>Coll<int>都应该是可能的).但我必须以不同方式测试引用和值类型.

拥有一个实现IsEmpty()方法的接口,从我的泛型类型中排除这个逻辑,这不是很好吗?但是,当然,这个IsEmpty()方法不能是成员函数:它无法在空对象上调用.

我找到的一个解决方法是将收集项目存储为对象,而不是Ts,但它让我头疼(围绕拳击和强类型).在旧的C++中没有问题:-)

下面的代码演示了我想要实现的目标:

using System;
using System.Collections.Generic;

namespace StaticMethodInInterfaceDemo
{
  public interface IEmpty<T>
  {
    static T GetEmpty();  // or static T Empty;

    static bool IsEmpty(T ItemToTest);
  }


  public class Coll<T> where T : IEmpty<T>
  {
    protected T[] Items;

    protected int Count;


    public Coll(int Capacity)
    {
      this.Items = new T[Capacity];
      this.Count = 0;
    }

    public void Remove(T ItemToRemove)
    {
      int Index = Find(ItemToRemove);

      // Problem spot 1: This throws a compiler error: "Cannot convert null …
Run Code Online (Sandbox Code Playgroud)

c# methods static interface

0
推荐指数
1
解决办法
770
查看次数

单身java模式

我仍然可以通过使用构造函数实例化,虽然在类定义中它已被声明为私有构造函数??? 这是代码片段:

public class Singleton {

  private static Singleton instance;
  private String name;

  /* Private constructor prevents other classes from instantiating */
  private Singleton(String name) {
    this.name = name;
    // Optional code
  }

  /*
   * Static factory method that creates instance instead of constructor.
   * Synchronization helps to block any attempt to instantiate from simultaneous
   * thread hence break concept of singleton.
   * This method uses a technique known as lazy instantiation.
   */
  public static synchronized Singleton getInstance(String name) { …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
383
查看次数

这在HTML和PHP中是可行的还是有效的?

我可以把它放在我的HTML中<head>吗?

<link rel="stylesheet" href="http://site.com/some/php/script/userid/style.php" />
Run Code Online (Sandbox Code Playgroud)

基本上,我可以通过URI段(或GET变量)将用户ID传递给PHP脚本 - 它仍然会被有效地视为样式表吗?

因此,例如,如果在我的webapp中用户的页面有自定义CSS样式表,我可以在控制器中动态加载它,将其作为样式表URL输出 - 这可能吗?我知道PHP部分肯定是可能的,但这仍然有效或完全兼容浏览器/服务器吗?

谢谢!

html css php

0
推荐指数
1
解决办法
96
查看次数

如何将字符数组复制到结构的成员?

我有这样的事情:

struct cd { char name; cd *next;}

// some code...

int main(){
char title[100];

// some code...

cd *p =new cd;
p->name=title;
Run Code Online (Sandbox Code Playgroud)

如何将阵列复制titlep->name

c++ arrays

0
推荐指数
1
解决办法
241
查看次数

隐藏复制构造函数C++

我想创建无法复制的类,所以我将复制构造函数放入私有部分:

class NotCopyable
{
public:
    NotCopyable(const double& attr1, const double& attr2) : _attr1(attr1), _attr2(attr2) {}
    ~NotCopyable(void) {}

private:
    NotCopyable& operator=(const NotCopyable&);
    NotCopyable(const NotCopyable&);
    double _attr1;
    double _attr2;
};
Run Code Online (Sandbox Code Playgroud)

一切都很好,除非我想分配数组:

NotCopyable arr[] =
{
    NotCopyable(1, 0),
    NotCopyable(2, 3)
};
Run Code Online (Sandbox Code Playgroud)

编译器说她无法访问复制构造函数,因为它在私有部分.当我把它放在公共部分时:

class NotCopyable
{
public:
    NotCopyable(const double& attr1, const double& attr2) : _attr1(attr1), _attr2(attr2) {}
    ~NotCopyable(void) {}
    NotCopyable(const NotCopyable&)
    {
        std::cout << "COPYING" << std:: endl;
    }
private:
    NotCopyable& operator=(const NotCopyable&);

    double _attr1;
    double _attr2;
};
Run Code Online (Sandbox Code Playgroud)

程序编译没有错误,但不调用复制构造函数.所以问题是:我如何禁止复制但仍有可能分配数组?

c++ copy-constructor

0
推荐指数
1
解决办法
497
查看次数

C++:声明指针

所以,在指南中,我读到了这句话

char * terry;
Run Code Online (Sandbox Code Playgroud)

不同于说

char* terry; //or
char *terry; // FYI: I understand what these two do.
Run Code Online (Sandbox Code Playgroud)

正如所述

"我想强调,*我们在声明指针时使用的星号()仅表示它是一个指针(它是其类型复合说明符的一部分),不应该与我们看到的取消引用运算符混淆早一点,但也用星号(*)写.它们只是两个不同的东西,用相同的符号表示."

但是我不明白为什么.也许我以错误的方式接受了引用,现在我再次阅读它,但我仍然感到困惑.任何人都可以告诉我这是错误的还是正确的,为什么?

谢谢.

c++ visual-studio

0
推荐指数
1
解决办法
239
查看次数

编译器如何工作,Makefile在前向声明的情况下发挥作用

我在堆栈溢出中遇到了一个建议,提到了何时使用以及何时不向用户转发声明.

我遇到了这个: -

struct X;              // Forward declaration of X

void f1(X* px) {}      // Legal: can always use a pointer/reference
X f2(int);             // Legal: return value in function prototype
void f3(X);            // Legal: parameter in function prototype
void f4(X) {}          // ILLEGAL: *definitions* require complete types`
Run Code Online (Sandbox Code Playgroud)

在编译时,最后一行说非法将失败.

void f3(X); // Works perfectly fine 
Run Code Online (Sandbox Code Playgroud)

因此,所有头文件(.hh)首先由编译器扫描,然后所有.cc文件寻找语法和语义,我们实际上可以定义
void f3(X);as扫描通过头文件编译器将有关于X的成员函数和成员的想法

c++ header-files

0
推荐指数
1
解决办法
143
查看次数