小编Mas*_*345的帖子

C++中的简单文件写入功能

我有这个代码:

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    writeFile();
}

int writeFile () 
{
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?它给了我错误:

1>------ Build started: Project: FileRead, Configuration: Debug Win32 ------
1>  file.cpp
1>e:\documents and settings\row\my documents\visual studio 2010\projects\fileread\fileread\file.cpp(8): error C3861: 'writeFile': identifier not …
Run Code Online (Sandbox Code Playgroud)

c++

36
推荐指数
4
解决办法
16万
查看次数

带有preg_replace的PHP过滤器只允许使用字母

我对preg_replace有点问题.我需要一个函数将所有字符转换为除了[A-z][0-9]和之外的所有字符. ! ?

我可以做一个preg_match,但这只是验证,我想要被替换.这不把垃圾字符像 <p>;[[;[p;[ 在描述元标记.

所以脚本必须像:

;")<br>kk23?! => brkk23?!

任何帮助将不胜感激:D

php regex

20
推荐指数
2
解决办法
5万
查看次数

PHP FTP ftp_nlist不工作​​,返回布尔值false

这个代码有点问题.脚本连接,但它不会给我位于根目录中的文件夹...我错过了什么?

    $ftp_server = "ftp.something.com";
    $ftp_user = "user";
    $ftp_pass = "pass";

    // set up a connection or die
    $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

    // try to login
    if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) 
    {
        echo "Connected as $ftp_user@$ftp_server\n";
    } 
    else 
    {
        echo "Couldn't connect as $ftp_user@$ftp_server\n";
    }

    $contents = ftp_nlist($conn_id, ".");
    var_dump($contents);

    ftp_close($conn_id);  

    die;
Run Code Online (Sandbox Code Playgroud)

它输出

Connected as $ftp_user@$ftp_server;
Run Code Online (Sandbox Code Playgroud)

boolean false
Run Code Online (Sandbox Code Playgroud)

为什么它不会列出文件?

我可以非常快速地解决这个问题

  file_exists("ftp//user:pass@host.com") 
Run Code Online (Sandbox Code Playgroud)

......但是容易的部分不是我想要的东西,我什么都不会学到

php ftp

14
推荐指数
2
解决办法
2万
查看次数

Heroku Git - 致命:远程端意外挂断

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

E:\Windows\system32>heroku login
Enter your Heroku credentials.
Email: mymail@yahoo.com
Password (typing will be hidden):
Found existing public key: E:/Users/Stewie/.ssh/id_rsa.pub
Uploading SSH public key E:/Users/Stewie/.ssh/id_rsa.pub... failed
 !    Fingerprint already exists. Please use one SSH key per Heroku account

E:\Windows\system32>git clone git@heroku.com:sharp-winter-5732.git -o heroku
Cloning into 'sharp-winter-5732'...

 !  Your key with fingerprint f2:a2:f9:4a:c4:16:5b:f1:5a:21:cb:d8:c4:d2:18:ef is
 not authorized to access sharp-winter-5732.

fatal: The remote end hung up unexpectedly

E:\Windows\system32>
Run Code Online (Sandbox Code Playgroud)

为什么我一直有这个错误?我该怎么办?并且不要给我一个减号,因为我已经看过了

https://help.github.com/articles/set-up-git

并给了我

E:\Windows\system32>git …
Run Code Online (Sandbox Code Playgroud)

git ssh rsa github

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

PHP中的简单JSON请求

我有以下json

country_code({"latitude":"45.9390","longitude":"24.9811","zoom":6,"address":{"city":"-","country":"Romania","country_code":"RO","region":"-"}})
Run Code Online (Sandbox Code Playgroud)

我只想要country_code,我如何解析它?

我有这个代码

<?php
$json = "http://api.wipmania.com/jsonp?callback=jsonpCallback";
$jsonfile = file_get_contents($json);

var_dump(json_decode($jsonfile));
?>
Run Code Online (Sandbox Code Playgroud)

它返回NULL,为什么?

谢谢.

php json file-get-contents

13
推荐指数
2
解决办法
6万
查看次数

在XSLT中动态包含其他XSL文件

我有一个小问题,有没有办法动态包含另一个xsl?例如:

<xsl:variable name="PathToWeb" select="'wewe'"/>
<xsl:include href="http://{$PathToWeb}/html/xsl/head.xsl" />
<xsl:include href="http://{$PathToWeb}/html/xsl/navigation.xsl" />
<xsl:include href="http://{$PathToWeb}/html/xsl/promo.xsl" />
<xsl:include href="http://{$PathToWeb}/html/xsl/3columns.xsl" />

<xsl:include href="http://{$PathToWeb}/html/xsl/footer.xsl" />
Run Code Online (Sandbox Code Playgroud)

xslt markup xslt-1.0

8
推荐指数
3
解决办法
9910
查看次数

MySQL INSERT INTO语法

我有以下结构

user_id int(11)
right   int(11)
group_id int(11)
value   tinyint(1)
Run Code Online (Sandbox Code Playgroud)

还有3个查询

INSERT INTO  user_rights (`user_id`,`right`,`group_id`,`value`)
VALUES ( '42',  '160',  '1',  '1' );

INSERT INTO  user_rights ('user_id','right','group_id','value')
VALUES ( '42',  '160',  '1',  '1' );

INSERT INTO  user_rights (user_id,right,group_id,value)
VALUES ( '42',  '160',  '1',  '1' );
Run Code Online (Sandbox Code Playgroud)

解释我为什么只有第一个有效????

我的一生都在使用第三个!

谢谢.

mysql sql sql-server mysqli

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

检查TELNET和PHP是否存在电子邮件

我在stackoverflow上看到了一些关于如何检查电子邮件是否存在的教程,我不太明白如何...

方法1

基本上我必须在cmd.exe中运行以下命令

telnet gmail-smtp-in.l.google.com 25
helo
mail from: <youremail@gmail.com>
rcpt to: <mailtocheck4@gmail.com>
Run Code Online (Sandbox Code Playgroud)

如果回复是"OK",那么我们会收到一封好的电子邮件.我在.bat文件中插入了所有这些内容,bat文件所做的只是连接到telnet并完成...

方法2

使用这个 http://www.geckotribe.com/php-telnet/#usage连接到telnet,但我不知道我应该提供什么密码

<?php
require_once "PHPTelnet.php";

$telnet = new PHPTelnet();

// if the first argument to Connect is blank,
// PHPTelnet will connect to the local host via 127.0.0.1
$result = $telnet->Connect('mail.gmail.com','usr','password');

if ($result == 0) 
{
    $telnet->DoCommand('helo', $result);
    // NOTE: $result may contain newlines
    echo $result;

    $telnet->DoCommand('another command', $result);
    echo $result;

    // say Disconnect(0); to break the connection without explicitly logging out …
Run Code Online (Sandbox Code Playgroud)

php gmail smtp telnet

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

XML DOM PHP将子节点添加到root/links/link

我有一个小问题......这是我的xml:

<?xml version="1.0" encoding="UTF-8"?>
<links>

    <link>
        <id>432423</id>
        <href>http://www.google.ro</href>
    </link>

    <link>
        <id>5432345</id>
        <href>http://www.youtube.com</href>
    </link>

    <link>
        <id>5443</id>
        <href>http://www.yoursite.com</href>
    </link>

</links>
Run Code Online (Sandbox Code Playgroud)

我怎么能和另一个人说话

    <link>
        <id>5443</id>
        <href>http://www.yoursite.com</href>
    </link>
Run Code Online (Sandbox Code Playgroud)

??

我设法只使用xpath向ROOT/LINKS添加记录 - > LINK,这是代码

<?php

$doc = new DOMDocument();
$doc->load( 'links.xml' );


$links= $doc->getElementsByTagName("links");

$xpath = new DOMXPath($doc);
$hrefs = $xpath->evaluate("/links");

$href = $hrefs->item(0);
$item = $doc->createElement("item");

    /*HERE IS THE ISSUE...*/
    $link = $doc->createElement("id","298312800");
    $href->appendChild($link);
    $link = $doc->createElement("link","www.anysite.com");
    $href->appendChild($link);

$href->appendChild($item);

print $doc->save('links.xml');

echo "the link has been added!";

?>
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激:D

php xml dom

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

来自MenuItem/MenuBar和Sound Player的Java Exit按钮

好吧,我在视频/学校的java学习中作为初学者编写了这段代码,我得到了一些问题.

1 =>为什么文件>退出按钮不起作用并且有一个小箭头,好像有一些孩子一样?大退出按钮使用相同的功能.我从这里受到启发:http://www.youtube.com/watch? src_vid = FB_wJpIdA8k&feature = iv&annotation_id = annotation_40248&v = dwLkDGm5EBc

2 =>如何让该按钮变小?当我调整它时,它会更大.

3 =>有谁知道一个简单的声音播放器库?那么当我按下那个按钮播放声音时?我已尝试过一些网络示例,例如http://www.developer.com/java/other/article.php/2173111/Java-Sound-Playing-Back-Audio-Files-using-Java.htm并且不知道如何使它变得简单,并在SoundPlay(sound.au)等各处使用它;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class form4 
{
    public static void main(String[] args)
    {
        // Frame
        JFrame frame = new JFrame("Menu");
        frame.setSize(300,300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Just create menubar
        JMenuBar menubar = new JMenuBar();
        frame.setJMenuBar(menubar);

        // Add an JMenu
        JMenu file = new JMenu("File");
        menubar.add(file); …
Run Code Online (Sandbox Code Playgroud)

java swing jframe jbutton actionlistener

3
推荐指数
1
解决办法
4万
查看次数

使用DOMDocument创建复杂的结构

使用PHP和Dom Document创建复杂的XML结构时遇到了一些问题.

我希望结构是这样的:

<page PathToWeb="www.mysite.com">
    <Questions>
        <Question id="my id" member="true">
        <Question id="my id2" member="true">
        <Question id="my id3" member="true">
    </Questions>
</page>
Run Code Online (Sandbox Code Playgroud)

我到目前为止的代码是

<?php
/*Create DOM*/
$xml = new DOMDocument;
$xml->load('myxml.xml'); /* wich is just just blank <?xml?\> <page> </page>*/
$xpath = new DOMXPath($xml);

/*Set the base path*/
$hrefs = $xpath->evaluate("/page");

/*Add Path to web to the root /page*/
$href = $hrefs->item(0);
$href->setAttribute("PathToWeb",$PathToWeb);


/*Complex XML Creation with Xpath*/

/*ELEMENT APPEND (create questions into /page)*/
$href = $hrefs->item(0);
$element = $xml->createElement('Questions');
$href->appendChild($element);

/*XPATH …
Run Code Online (Sandbox Code Playgroud)

php xml xpath dom

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

线程完成后检查执行代码

我没有完全理解线程的概念我有一些问题.假设我们有以下代码:

ExecCommand.java

// I don't know how this work, for now
package therads;

// Here we will have the methods and run them from the Main.java
public class ExecCommand implements Runnable
{
    String name;
    int time;

    public ExecCommand(String s,int amount)
    {
        name = s;
        time = amount;
    }

    // Run method (Runnable)
    public void run()
    {
        try
        {
            // What to execute when the thread is started
            System.out.printf("%s is sleeping for %d\n",name,time);
            Thread.sleep(time);
            System.out.printf("%s is done\n",name);
        }
        catch(Exception e)
        { …
Run Code Online (Sandbox Code Playgroud)

java multithreading

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