File:开发者_如何学运维 sub.cpp
// The string to print
char str[] = "Hello World!\n";
File: main.cpp
/************************************************
 * print string -- Print a simple string. *
 ************************************************/
#include <iostream>
extern char *str; // The string to print
int main()
{
    std::cout << str << std::endl;
    return (0);
}
The next time you find yourself somewhere wanting to know what a snippet of C++ code does, but without a compiler handy to test it for yourself, try codepad.org. Here's the output of your sample code:
Line 9: error: conflicting declaration 'char* str' compilation terminated due to -Wfatal-errors.
As Benoit mentioned in a comment, you have declared str in one place as char* and in another as char[]. Those two types are incompatible, and that gives the linker a fit.
Changing the declarations to match will produce the following output, as probably expected:
Hello World!
I'm not sure why you expect that the results will be different in Visual C++, much less in "Debug" mode.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论