[英]Why am I receiving C2440 error for string when trying to open file using <netcdf> library?
[英]I am trying to reverse a string using simple stack push and pop. However I am receiving some error that I am not able to make sense of
我的代碼:
#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
。 如果它不能編譯,請告訴我錯誤是什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.