我正在尝试使用简单的堆栈推送和弹出来反转字符串。但是,我收到一些我无法理解的错误

阿育王

我的代码:

#include<iostream>
#include<stack>
using namespace std;


void Reverse_string(char *C, int n)
{
    stack<char> S;
    for(int i =0; i < n ; i++)
    {
        S.push(C[i]);
    }

    for(int i = 0; i< n; i++)
    {
        C[i] = S.top();  //overwite the char at index i
        S.pop();
    }

}
int main()
{
    char C[51]= "Hello WOrld";

    Reverse_string(C,11);
    printf("Output = %s", C);
} 


错误:

/tmp/ccC6pV6B.o: In function `__static_initialization_and_destruction_0(int, int)':
reverse_stack.cpp:(.text+0x1bb): undefined reference to `std::ios_base::Init::Init()'
reverse_stack.cpp:(.text+0x1d0): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccC6pV6B.o: In function `std::_Deque_base<char, std::allocator<char> >::_Deque_impl::~_Deque_impl()':
reverse_stack.cpp:(.text._ZNSt11_Deque_baseIcSaIcEE11_Deque_implD2Ev[_ZNSt11_Deque_baseIcSaIcEE11_Deque_implD5Ev]+0x14): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccC6pV6B.o: In function `std::_Deque_base<char, std::allocator<char> >::_Deque_impl::_Deque_impl()':
reverse_stack.cpp:(.text._ZNSt11_Deque_baseIcSaIcEE11_Deque_implC2Ev[_ZNSt11_Deque_baseIcSaIcEE11_Deque_implC5Ev]+0x14): undefined reference to `std::allocator<char>::allocator()'
/tmp/ccC6pV6B.o: In function `std::_Deque_base<char, std::allocator<char> >::_M_initialize_map(unsigned long)':
reverse_stack.cpp:(.text._ZNSt11_Deque_baseIcSaIcEE17_M_initialize_mapEm[_ZNSt11_Deque_baseIcSaIcEE17_M_initialize_mapEm]+0x16b): undefined reference to `__cxa_begin_catch'
reverse_stack.cpp:(.text._ZNSt11_Deque_baseIcSaIcEE17_M_initialize_mapEm[_ZNSt11_Deque_baseIcSaIcEE17_M_initialize_mapEm]+0x1a5): undefined reference to `__cxa_rethrow'
reverse_stack.cpp:(.text._ZNSt11_Deque_baseIcSaIcEE17_M_initialize_mapEm[_ZNSt11_Deque_baseIcSaIcEE17_M_initialize_mapEm]+0x1ad): undefined reference to `__cxa_end_catch'
/tmp/ccC6pV6B.o: In function `__gnu_cxx::new_allocator<char>::deallocate(char*, unsigned long)':
reverse_stack.cpp:(.text._ZN9__gnu_cxx13new_allocatorIcE10deallocateEPcm[_ZN9__gnu_cxx13new_allocatorIcE10deallocateEPcm]+0x1c): undefined reference to `operator delete(void*)'
/tmp/ccC6pV6B.o: In function `std::_Deque_base<char, std::allocator<char> >::_M_create_nodes(char**, char**)':
reverse_stack.cpp:(.text._ZNSt11_Deque_baseIcSaIcEE15_M_create_nodesEPPcS3_[_ZNSt11_Deque_baseIcSaIcEE15_M_create_nodesEPPcS3_]+0x48): undefined reference to `__cxa_begin_catch'
reverse_stack.cpp:(.text._ZNSt11_Deque_baseIcSaIcEE15_M_create_nodesEPPcS3_[_ZNSt11_Deque_baseIcSaIcEE15_M_create_nodesEPPcS3_]+0x64): undefined reference to `__cxa_rethrow'
reverse_stack.cpp:(.text._ZNSt11_Deque_baseIcSaIcEE15_M_create_nodesEPPcS3_[_ZNSt11_Deque_baseIcSaIcEE15_M_create_nodesEPPcS3_]+0x6c): undefined reference to `__cxa_end_catch'
/tmp/ccC6pV6B.o: In function `__gnu_cxx::new_allocator<char*>::deallocate(char**, unsigned long)':
reverse_stack.cpp:(.text._ZN9__gnu_cxx13new_allocatorIPcE10deallocateEPS1_m[_ZN9__gnu_cxx13new_allocatorIPcE10deallocateEPS1_m]+0x1c): undefined reference to `operator delete(void*)'
/tmp/ccC6pV6B.o: In function `__gnu_cxx::new_allocator<char>::allocate(unsigned long, void const*)':
reverse_stack.cpp:(.text._ZN9__gnu_cxx13new_allocatorIcE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorIcE8allocateEmPKv]+0x2c): undefined reference to `std::__throw_bad_alloc()'
reverse_stack.cpp:(.text._ZN9__gnu_cxx13new_allocatorIcE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorIcE8allocateEmPKv]+0x38): undefined reference to `operator new(unsigned long)'
/tmp/ccC6pV6B.o: In function `__gnu_cxx::new_allocator<char*>::allocate(unsigned long, void const*)':
reverse_stack.cpp:(.text._ZN9__gnu_cxx13new_allocatorIPcE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorIPcE8allocateEmPKv]+0x2c): undefined reference to `std::__throw_bad_alloc()'
reverse_stack.cpp:(.text._ZN9__gnu_cxx13new_allocatorIPcE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorIPcE8allocateEmPKv]+0x3c): undefined reference to `operator new(unsigned long)'
/tmp/ccC6pV6B.o:(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
阿鲁斯·阿加兰普尔

您似乎在链接到C ++运行时库时遇到问题。出于某种原因,编译器可能正在尝试以C模式进行编译。我假设您使用Linux作为操作系统。

尝试命令g++ program.cpp -o program如果无法编译,请告诉我错误是什么。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我正在为字符串编写一些函数,但是我对realloc有问题

我已经写了一些代码,我正在尝试使用“else”,但我不断收到错误

我正在尝试通过 espeak 传递一些字符串,它会读取它们,但出现“分段错误”

我正在使用while循环反转C#中的字符串,我得到正确的输出,但是与for循环一起使用的逻辑相同,然后输出错误

我想使用numpy分析一些数据,但是执行代码时错误不断弹出

我正在尝试将值添加到数据库中,但是每次我尝试添加一些东西时,我都会收到错误消息“连接必须有效且打开”。

我无法理解C#的统一和错误的简单答题器

我已经编写了用于反转字符串的代码。但是在输出中它会产生一些垃圾。为什么?

使用堆栈反转字符串对我不起作用

我正在尝试使用Datastax 4.2.2编写DAO接口,但遇到一些编译错误

我正在尝试从网页中抓取一些数据并不断收到 selenium.common.exceptions.TimeoutException 错误

我正在尝试使用一种形式在db中保存多个记录,但是却出现此错误:数组到字符串的转换

我正在尝试使用 Glade 在 GTK+ 上做一个项目,但是当我编译我的代码并运行可执行文件时,我遇到了一些错误

我正在尝试使用来自sklearn的Python MultinomialNB对一些数据进行分类,但是它返回值错误

我正在尝试使用python 3.8获得日语句子。但是我只是弄懂一些难以理解的人物,有人可以帮我吗?

您好,我只是想知道什么是PL / SQL Lexer错误:未终止的字符串表示什么?我一直在研究它,但似乎无法理解

我正在尝试将对象中的一些值推送到 3 维数组中

Flutter 中的列表视图,我正在尝试但无法理解实际错误是什么

我正在尝试删除一些电子邮件,但是当我运行代码时出现以下错误: TypeError: 'module' object is not callable (env)

我想使用memset从字符串中删除一些字符

我正在django中使用celery发送注册激活电子邮件,但是celery提供了一些错误

我正在尝试在node.js项目中的模块之间传递数据,但是我丢失了一些东西

我正在尝试合并为整数字符串,但是Dr. Java我正在使用的程序不会让我使用ArrayUtils吗?

Python海龟函数 - 收到一个我无法理解的错误

我正在尝试创建并调用一个函数来反转字符串并删除小数点前的整数

我自己的子字符串函数 valgrind显示一些我不明白的malloc错误

我正在尝试使用向后勾来调出包含我的ID和密钥的函数。但是我收到了作为意外令牌的错误

使用sed我只想在行中打印一些字符串

我正在尝试在parse.com中编写触发器,但出现一些错误