我正在寻找一种解决方案,将硬盘上的本机操作系统作为虚拟机启动.
这就像VMware Fusion在Mac上作为虚拟机在Boot Camp中启动Windows所做的事情.
详细说来,我在/ dev/sda2上安装了Windows,在/ dev/sda5上安装了Ubuntu 11.10.
无论如何使用虚拟机软件在我使用Ubuntu时将/ dev/sda2上的Windows作为虚拟机启动?
有没有办法在Visual Studio中捕获stdout和stderr?例如,当我使用时
cout <<"Hello world!"<< endl;
Run Code Online (Sandbox Code Playgroud)
出现黑色窗口并消失.它太快了,我看不到它.IDE中有一个输出部分,但它只允许我从构建中选择显示输出,而不选择stdout.
作弊解决方案可能会打电话
system("pause");
Run Code Online (Sandbox Code Playgroud)
但听起来不对.我在选项中搜索但我找不到一个项目.
任何人有任何想法?谢谢.我刚开始使用VS而且我之前在Linux上.
我正在编写一个包含许多可用设置的java应用程序.基本上我的配置结构如下所示:
Config |_ game 1 |_ Game name: blah... |_ Player name: alice |_ Player name: bob |_ other settings... |_ game 2 |_ Game name: hah |_ Player name: alice |_ Player name: bob |_ other settings... |_ game n....
你明白了.我尝试使用xml但是使用dom4j是一种痛苦,特别是在不同和相同的父节点中有很多具有相同名称的子节点,我需要对它们进行大量更改.到目前为止,我发现最简单的方法是使用纯文本文件
[Game 1] Game name: blah Player name: alice Player name: bob ... [Game 2] ...
但我觉得这是非常简陋的.那么在java中维护配置文件的行业最佳或标准做法是什么?
编辑:我希望解决方案是可移植的,比如将文件从一台计算机复制到另一台计算机不会破坏程序.(抱歉忘记提前了.)
我正在尝试使用Java中的DOM读取XML
<?xml version="1.0"?>
<record>
<user>
<name>Leo</name>
<email>****@****.com</email>
<food-list>
<food>Hamburgers</food>
<food>Fish</food>
</food-list>
</user>
</record>
Run Code Online (Sandbox Code Playgroud)
我目前的解决方案是
for (int userNumber = 0; userNumber < masterList.getLength(); userNumber++) {
Node singleUserEntry = masterList.item(userNumber);
if (singleUserEntry.getNodeType() == Node.ELEMENT_NODE) {
org.w3c.dom.Element userEntryElement = (org.w3c.dom.Element) singleUserEntry;
System.out.println("name : " + getTagValue("name", userEntryElement));
System.out.println("email : " +getTagValue("email", userEntryElement));
NodeList foodList = userEntryElement.getElementsByTagName("food-list").item(0).getChildNodes();
for(int i = 0; i < foodList.getLength(); i++){
Node foodNode = foodList.item(i);
System.out.println("food : " + foodNode.getNodeValue());
}
private static String getTagValue(String sTag, org.w3c.dom.Element eElement) {
NodeList …Run Code Online (Sandbox Code Playgroud) 我几乎同时在两个线程上初始化两个随机数生成器,我希望两个生成器的行为完全不同.我会Random.nextInt(7)经常一个接一个地打电话给两台发电机.使用System.currentTimeMillis()不是一个好主意,因为看起来我的电脑速度太快,以至于从两台发电机获得的数字很可能是相同的.那么有没有办法配置,Random所以虽然它们被一个接一个地调用,但它们仍然表现不同?我希望该解决方案能够跨平台兼容,因此任何特定于平台的想法(例如读取)/dev/random都是不可接受的.感谢帮助.
我是一名新程序员,我想出了一个内存泄漏问题.如果我在循环中声明一个变量以使其一次又一次地被声明,我是否会泄漏内存?例如,我有
while(true)
{
Image<Gray, Byte> MyImage = new Image<Gray, Byte> (1024, 768);
//do something else
}
Run Code Online (Sandbox Code Playgroud)
我知道这是一个无限循环,但我的问题是关于记忆.此循环中的内存使用量是否快速增长?我应该手动发布MyImage吗?
看看在这里找到的这个片段
进口 (
“编码/xml”
“FMMT”
“操作系统”
)
函数主() {
类型地址结构体{
城市、州字符串
}
类型 Person 结构 {
XMLName xml.Name `xml:"person"`
Id int `xml:"id,attr"`
名字字符串 `xml:"name>first"`
姓氏字符串 `xml:"name>last"`
年龄 int `xml:"年龄"`
高度 float32 `xml:"height,omitempty"`
已婚布尔
地址
注释字符串 `xml:",comment"`
}
v := &Person{ID:13,名字:“John”,姓氏:“Doe”,年龄:42}
v.Comment =“需要更多详细信息。”
v.Address = 地址{"安加罗阿", "复活节岛"}
enc := xml.NewEncoder(os.Stdout)
enc.缩进(“”,“”)
if err := enc.Encode(v); 错误!=零{
fmt.Printf("错误: %v\n", err)
}
}
我可以理解struct Person,它有一个名为 var Id,它是类型的int,但是这些东西呢
xml:"person" 在 int 之后?这是什么意思?谢谢。 我有 C 代码做一些计算(我相信与我的问题无关)。程序会要求一些参数进行计算。问题是当我运行代码时, scanf("%c", &ch) 无法正常工作。
我感兴趣的是你是否可以重现这个问题,因为我似乎没有做错什么,不是吗?
我发布了我的程序的可编译和缩短版本。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void)
{
float Dia_MM, Dia_I, Se1, Se, Sut = 75.00;
float Ka, Kb, Kc, Kd, Ke, Kf;
char Ch;
char Bt;
float Reli;
printf("Please input the surface condition of the shaft: G, M, H or A\n");
scanf("%c", &Ch);
// getchar();
printf("Please input the diameter of the shaft in inch\n");
scanf("%f", &Dia_I);
printf("Please specify whether your shaft is in bending (B) or torsion (T)");
scanf("%c", &Bt);// THIS LINE IS …Run Code Online (Sandbox Code Playgroud) 我正在使用fstream打开文件进行写入.我不想覆盖现有文件,所以经过一些搜索后,我找到了ios :: noreplace.但是当我编译它时:
#include <fstream>
using namespace std;
//......Did something else.
ofstream fout;
fout.open(outputFile,ios::noreplace);//outputFile is a C string
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
error: ‘noreplace’ is not a member of ‘std::ios’
Run Code Online (Sandbox Code Playgroud)
我只是想知道ios :: noreplace有没有std :: subsitution?
有很多代码按字典顺序对字符串数组进行排序,但我找不到按字典顺序对字符串进行排序的字符串.到目前为止,我发现使用std::sort()in <algorithm>可能是最接近的候选者.
这是我试过的:
template <typename T>
class ReverseComparator{
bool operator()(T l, T r){return !(l < r);}
};
//.....later
std::sort(str.begin(), str.end(), comparator);
Run Code Online (Sandbox Code Playgroud)
这是一个问题:如何初始化我的比较器,以便它可以比较字符串中的字符?我试过,ReverseComparator<char> comparator但编译器抛出了大量的错误信息. gcc-4.5.1显示了以下错误:
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/algorithm:63:0,
from prog.cpp:1:
prog.cpp: In function 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2192:4: instantiated from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5252:4: instantiated from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, …Run Code Online (Sandbox Code Playgroud) 我知道很多人都遇到这个错误.我确实做了搜索工作,但似乎这个错误消息出现在所有不同的情况下.你能告诉我什么是错的吗?基本上这个类存储一个长输入的int数组.这个错误在函数num()中
还有一个错误:
main.cpp:43: error: invalid conversion from ‘num*’ to ‘long int’
main.cpp:43: error: initializing argument 1 of ‘num::num(long int)’
#include <iostream>
#include <fstream>
using namespace std;
//ifstream fin;
//ofstream fout;
class num
{
public:
int dig[9];
void breakDown(long input)
{
for(int digPos=0;input>0;digPos++)
{
dig[digPos]=input-((int)input/10)*10;
input=(int)input/10;
}
}
num(long in) // constructor
{
breakDown(long in);
}
int outPut()
{
for(int digPos=0;digPos<9;digPos++)
{
cout << dig[digPos];
}
return 0;
}
};
//int init()
//{
// fin.open("runround.in",ifstream::in);
// fout.open("runround.out");
//}
int main()
{ …Run Code Online (Sandbox Code Playgroud) 有没有办法在课外调用函数?我不知道怎么说,但我有一个例子.
class Class1{
class Class2{
public void callFunctionInC1(){
//how can I call funtionNeedtoBeCalled
}
}
public Class1(){
Class2 c2 = new Class2();
c2.callFunctionInC1();
}
public void functionNeedtoBeCalled(){
//do something
}
}
Run Code Online (Sandbox Code Playgroud)
这听起来很奇怪,但我确实有理由这样做.反正有吗?谢谢.
有人可以向我解释为什么这会打印出0而不是2?这里肯定会有一些简单的(读作愚蠢的)错误,但我无法弄明白.谢谢.
public class test{
public static void main(String[] args){
int result[] = new int[]{0,0,1,0};
int out = 0;
for(int i = 0;i < result.length; i ++){
out = out << 1 + result[i];
}
System.out.println(out);
}
}
Run Code Online (Sandbox Code Playgroud)