我正在尝试在用户输入的字符串中查找空间.我想用find()from std::string来返回空间的位置.
如果输入是"Seattle,WA USA",我想要find(" ", 0)返回8,我该怎么做?第8个是","之后的空格
string inputString = " ";
cout << "Enter String to modify" << endl;
cin >> inputString;
int spac = inputString.find(" " , 0);
Run Code Online (Sandbox Code Playgroud)
但是find()继续回来0.我不知道为什么.
我有一个方法,将txt文件作为输入.我曾经通过键入文件的直接路径来使用字符串.但每当我尝试使用不同的文件进行输入时,它就会变得很麻烦.我尝试实施,JFileChooser但没有运气.
这是代码,但没有发生任何事情.
public static JFileChooser choose;
File directory = new File("B:\\");
choose = new JFileChooser(directory);
choose.setVisible(true);
File openFile = choose.getSelectedFile();
FileReader fR = new FileReader(openFile);
BufferedReader br = new BufferedReader(fR);
Run Code Online (Sandbox Code Playgroud) 在C#中,在Windows窗体中将控制台输出定向到文本框的好方法是什么?
如果我有一个具有console.WriteLine的现有程序,我是否需要重载Windows窗体文本框中的函数?
我的同伴告诉我,我实施以下方式是一种危险的做法.我在main方法和函数中为变量添加了相同的名称.我的意思是只要它有效,是不是没问题?你会怎么做不同的?
谢谢.
#include <iostream>
#include <string>
#include <sstream>
#include "Three.h"
Three::Three(void)
{
}
Three::~Three(void)
{
}
void Three::rect (int& ar, int&vl, int len, int wid, int hgt)
{
ar = (len * wid) * 2 + (len+wid) * 2 * hgt;
vl = len * wid * hgt;
cout << "Area is " << ar << " square feet that contains " << vl << " cubic feet." << endl;
}
char qt;
int main (int, char**)
{
int len …Run Code Online (Sandbox Code Playgroud) 以下是我作为课程练习所做的Java代码.我有一个名为SavingsAccount的类.它有平衡和利息变量.但是,我将它们设置为公开,但如果我想单独处理帐户,我是否需要将它们设为私有并为这些变量设置"获取/设置"方法?我可以不公开变量公开吗?其余代码具有使用这些变量计算的方法.
public class SavingsAccount { //This class has three different variables that define it
public double balance; //Double for account balance
public static double annualInterestRate; //Class method for interest rate
public final int ACCOUNT_NUMBER; //Constant int for keeping track of accounts
public SavingsAccount (int ACCOUNT_NUMBER, double balance) { //Constructor that takes down account number and balance to keep track of
this.ACCOUNT_NUMBER = ACCOUNT_NUMBER;
this.balance = balance;
}
Run Code Online (Sandbox Code Playgroud) 我正在用C++实现一个简单的优先级队列.
然而,当它运行时,它打印出乱码数字.我在某种程度上试图在我的代码中访问数组中的无效条目?
下面是代码.
另外,我的"删除"功能是不是在做它的工作?从概念上讲,我应该将null放入第一个条目并返回刚删除的内容吗?
谢谢.
[Priority.h]
#ifndef Priority_h
#define Priority_h
class Priority
{
public:
Priority(void);
Priority(int s);
~Priority(void);
void insert(long value);
long remove();
long peekMin();
bool isEmpty();
bool isFull();
int maxSize;
long queArray [5];
int nItems;
private:
};
#endif
Run Code Online (Sandbox Code Playgroud)
[Priority.cpp]
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include "Priority.h"
using namespace std;
Priority::Priority(void)
{
}
Priority::Priority(int s)
{
nItems = 0;
}
Priority::~Priority(void)
{
}
void Priority::insert(long item)
{
int j;
if(nItems==0) // if no items,
{
queArray[0] = …Run Code Online (Sandbox Code Playgroud)