- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试将 cfg 读入多重链接列表,但我收到此错误,请有人帮忙。它不断给出这个错误。我不认为有什么错误。请检查这段代码并告诉我哪里有错误导致程序崩溃并出现图片中所附的异常
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
struct prod_list{
string production;
struct prod_list *next;
}*head_p=NULL;
//Node for linked list to store Non terminals
struct rule_list{
char non_terminal;
struct prod_list *first;
struct rule_list *next;
}*head_r=NULL;
// Global variable
struct prod_list *temp_p,*prev_p=NULL,*first_p=NULL,*temp1_p=NULL,*temp2_p,*newTemp;
struct rule_list *temp_r,*prev_r=NULL,*first_r=NULL ,*temp1_r=NULL;
prod_list *adding_productions_of_the_rule(string line);
prod_list *add_node(prod_list *root, string production);
int main()
{
string line;
ifstream file ("cfg.txt");
if (file.is_open())
{
while ( getline (file,line) )
{
head_p = NULL;
// Creating rule_list node
temp_r = new rule_list;
temp_r->non_terminal = line[0];
head_p = adding_productions_of_the_rule(line);
temp_r->first = head_p;
temp_r->next = NULL;
if(head_r == NULL)
{
head_r = temp_r;
prev_r = temp_r;
}
else
{
prev_r->next = temp_r;
prev_r = temp_r;
}
}
file.close();
}
else
{
cout << "Unable to open file";
}
return 0;
}
prod_list *adding_productions_of_the_rule(string line)
{
string prod = NULL;
// Splitting line after arrow in cfg rule line.
line = line.substr(3,line.length());
// cout << "The cfg is "+line << endl;
// declaring character array of line's length
char ch[line.length()]={0};
// memset(ch,'0',line.length());
// cout << sizeof(ch) << endl;
// storing line in character array and printing character array
for(int i=0; i<line.length(); i++){
ch[i] = line[i];
// Displaying the characters stored in character array from string line.
// cout << ch[i];
}
// cout << endl;
char *point;
point = strtok(ch, "|");
while(point != NULL){
// cout << point << endl;
// Assigning each production from the cfg rule to an array of strings
// production[i] = point;
// cout << production[i] << endl;
// Creating prod_list node
prod = point;
head_p = add_node( head_p, prod );
point = strtok(NULL, "|");
// i++;
}
return head_p;
}
prod_list *add_node(prod_list *root, string production){
prod_list *next_ptr = NULL;
prod_list *prev_ptr = NULL;
if(root == NULL){
//list is empty
if( (root = new prod_list) != NULL){
next_ptr = root;
// cin >> next_ptr->title;
next_ptr->production = production;
next_ptr->next = NULL;
}else{
cout << "Error: Unable to allocate memory. " << endl;
return NULL;
}
return next_ptr;
}else{
//list has members.
next_ptr = root;
while(next_ptr->next != NULL){
next_ptr = next_ptr->next;
}
prev_ptr = next_ptr;
if((next_ptr = new prod_list)!= NULL){
prev_ptr->next = next_ptr;
next_ptr->production = production;
next_ptr->next = NULL;
}else{
cout << "Error: Unable to allocate memory " << endl;
}
}
return root;
}**I have been trying to read cfg into a multilinklist but im getting this error please someone help **
最佳答案
您的错误可以减少到最小的情况:
#include <string>
int main() {
std::string prod = NULL;
}
发生的事情是试图从 NULL 指针中创建一个 std::string
。显然,字符串
没有任何东西可以使用,所以它做了它唯一能做的事情:尖叫求救。
解决方案:
不要分配任何东西。 std::string
将默认构造一个空字符串。
关于c++ - 抛出 'std::logic_error' What() 的实例后调用终止: basic_string::_S_construct null 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40826885/
ninja (版本:1.9.0)输出: mergetree_test.cpp:(.text+0x19f): undefined reference to `DB::executeQuery(std::
嘿,我正在制作“制作你自己的冒险游戏!”现在除了必须通过漏洞游戏之外,我想制作一个作弊代码系统,现在我试图声明一个字符串女巫等于超过 6 个单词我不明白问题是什么我只用了两个单词并且没有错误但是当我用
在 MacOS X 10.10 CLang 中: typedef basic_string, allocator > string; typedef basic_string, allocator >
来自以下内容 Can I turn unsigned char into char and vice versa? 似乎转换 basic_string到 basic_string (即 std::st
我这样定义一个字符串对象: string test; 我想知道STL是怎么实现string的,发现string是basic_string,像这样: typedef basic_string st
好吧,我有这个代码: #include #include "Stack.h" #include using namespace std; int main(int argc, char* argv
当我编译以下 MWE 时出现上述错误在 GCC 上 #include void frobnigate( const std::string& str ) { std::string::con
我正在尝试编译 QtWebApp使用 Qt5.5.1 到最新的 RPI4-Raspbian Buster,我遇到了莫名其妙的 GLIBCXX 未解析符号 什么有效:QtWebApp 使用在 Raspb
尽管以下代码可以在 Linux 上编译,但我无法在 Windows 上编译它: boost::filesystem::path defaultSaveFilePath( base_directory
我在函数的代码行下面运行 string internalPath(os.str()); m_tags.insert(make_pair(internalPath, tagConfig )); e
如何把所有的\都改成\\? 我想创建地址来处理文件: #include #include #include using namespace std; int main() { strin
我目前正在为一个类项目工作,其中我必须在 C++ 中实现布谷鸟哈希。问题是,C++ 和我从来都不是 friend ,而且我认为我们永远不会... 具体的问题是,我无法在已经存在的对象上设置指针。当我这
你能告诉我这段代码有什么问题吗?关于如何修复的任何想法? JNIEXPORT jstring JNICALL Java_COM_DEMO_TEST_SEND (JNIEnv *env, jclass
所以我是编程新手,这是大学工程类(class)的一部分。我决定找点乐子,在课外写点东西。我正在尝试用 C++ 编写一个程序,允许用户输入 3 个矩形棱柱的长度、宽度和高度值,程序将使用这 3 个值来计
我将重新发布我今天早些时候提交的问题,但现在我引用一个具体示例来回应我收到的反馈。可以在here中找到原始问题(请注意,这不是家庭作业): 我只是试图确定C++是否使不可能对basic_string对
当我尝试编译以下代码时: #include using namespace std; typedef std::basic_string foostring; foostring foo = "fo
我正在评估使用 basic_string 模板来实现一个类似字符串的对象,以便使用外部内存管理器进行分配。该内存管理器保持已分配内存的最大大小和当前大小(允许当前大小增加到最大大小)。为了避免冗余,我
我有一个函数,ModuleManager::tick(),代码如下: void ModuleManager::tick() { auto now = std::chrono::steady_clock
我正在完成自定义字符串类的开发。当然,它的目的是等同于 basic_string,并为其预期目的定制了内部存储。我正在寻找一种测试工具,它可以按照 C++ 标准进行测试。我已经看到 libstdc++
在浏览 C++14/C++1y (n3690) 草案时,我注意到在第 21.7 节中引入了 basic_string 文字后缀: inline namespace literals { inline
我是一名优秀的程序员,十分优秀!