我在我的c ++代码中得到此错误非POD元素类型string(aka basic_string<char>)的可变长度数组.
string words[numWords];
Run Code Online (Sandbox Code Playgroud)
如果我摆脱numWords并输入一个数字,这工作正常,但如果我把相同的数字放在一个变量,它给我Variable length array of non-POD element type 'string' (aka 'basic_string<char>')错误,我已经这样做过,它在视觉工作室工作,但我现在在Xcode中尝试过它不起作用.我已经尝试过使用矢量,但我无法让它们存储任何数据,它们只是空白.
对于那些问我这是我的矢量代码的人应该都在那里
char ch;
ifstream repFile("//Users//bobthemac//Documents//c++asignment//c++asignment//test1.txt");
while(repFile.get(ch))
{
if(ch == ' ' || ch == '\n' || ch == '\t')
{
numWords++;
}
}
vector<string> words (numWords);
while(repFile >> x)
words.push_back(x);
repFile.close();
Run Code Online (Sandbox Code Playgroud) 我想获得存储在矢量中的单词的频率.我已多次用Google搜索我的问题,而不是去找对我有用的东西.我找到了一个网站,有人说使用该unique命令来计算单词的频率,但我找不到任何关于如何完成这个的例子.
使用此代码删除重复项时,我得到二进制表达式错误的无效操作数.我认为这取决于使用结构的向量,但我不确定我用Google搜索了我的问题,我一遍又一遍地得到这个代码,这表明这段代码是正确的,但它对我不起作用.
std::sort(vec.begin(), vec.end());
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
编辑:
fileSize = textFile.size();
vector<wordFrequency> words (fileSize);
int index = 0;
for(int i = 0; i <= fileSize - 1; i++)
{
for(int j = 0; j < fileSize - 1; j++)
{
if(string::npos != textFile[i].find(textFile[j]))
{
words[i].Word = textFile[i];
words[i].Times = index++;
}
}
index = 0;
}
sort(words.begin(), words.end());
words.erase(unique(words.begin(), words.end(), words.end()));
Run Code Online (Sandbox Code Playgroud) 这段代码有效,但有点限制,所以如果它不等于一个字母,我想删除一些东西.
我知道我必须使用:: isalpha而不是:: ispunct但我不明白如果它不等于:: isalpha,如何删除它.我已经解决了这个问题,但没有得到答案,因为我不理解它们.
textFile[i].erase(remove_if(textFile[i].begin(), textFile[i].end(), ::ispunct), textFile[i].end());
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
我无法访问我的两个变量.我在互联网上看了一下,发现我需要使用类似的东西form.dlg.selectedpath来调用它,但我得到了三个错误.有人说form.dlg无法访问,下一个说需要对象引用.我也尝试访问另一个,并说表单不包含dlg2的定义.
这是我想要变量的代码.
var di = new DirectoryInfo(Form1.dlg.SelectedPath);
di.CopyTo(Form1.dlg2.SelectedPath, true);
Run Code Online (Sandbox Code Playgroud)
这是我的代码我正在设置一个变量
public partial class Form1 : Form
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
if (dlg.ShowDialog() == DialogResult.OK)
Run Code Online (Sandbox Code Playgroud)
第二个变量从这里引用.
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg2 = new FolderBrowserDialog();
if (dlg2.ShowDialog() == DialogResult.OK)
//do whatever with dlg.SelectedPath
{
backgroundWorker1.RunWorkerAsync(dlg2.SelectedPath);
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
我有点麻烦让这个c#代码工作我可以让它工作,如果我使用我已注释掉的console.write但我可以得到存储在这个数组中的相同结果供我在不同的部分使用我的节目.
FileInfo[] selectionFileOrder;
for (int index = 0; index < dateAllOrder.Length; index++)
{
if (dateAllOrder[index].LastAccessTime.Month == DateTime.Now.Month)
{
int i = 0;
i++;
selectionFileOrder[i] = dateAllOrder[index];
// Console.Write("{1}. {0}", dateAllOrder[index].Name, index);
// Console.Write(" ({0}) ", dateAllOrder[index].Length);
Console.WriteLine();
}
}
Run Code Online (Sandbox Code Playgroud)
我看过谷歌,似乎无法找到我的问题的任何答案我知道它是变量selectionFileOrder是无符号的,但我没有任何分配给它.任何新鲜的想法都会有所帮助
谢谢
我不知道是不是我只是厚,但我有一些验证码来检查是或否答案.
我似乎无法让它工作我已经在我的程序中的其他地方使用了代码并且它可以工作,但是如果有的话我无法发现错误.无论如何,代码都会贯穿整个输入字符.
string correctDestenation = Console.ReadLine().ToLower();
while (correctDestenation != "y" || correctDestenation != "n")
{
Console.WriteLine(
"Oops! You must enter a 'y' for yes and a 'n' for no");
correctDestenation = Console.ReadLine().ToLower();
}
Run Code Online (Sandbox Code Playgroud)