Hi,

I am still new to C++ and I am having a little trouble compiling the following code, and couldn't figure out what went wrong:

#include <iostream.h>
#include <string.h>

using namespace std;

float x = 5.0f;
int _65Num = 65;

int mian()
{
    string str = "Hello World!";
    cout << str << endl;
    cout << x << "" << str << endl;
    cout << "65Num = " << _65Num << endl;
}

The question ask me to identify the problem which I tried to correct as much as I can but I still get some problem while compiling...

The original code was this:

#include <iostream.h> #include <string.h>

int mian()
{
    string str = "Hello World!"
    cout << str << endl;
    cout << float x = 5.0f * str << end;
    int 65Num = 65;
    cout << "65Num = " < 65Num << endl;
}

Hope someone can point me in the right direction.

Dani AI

Generated

Small, common mistakes explain the compile failures in 's thread. 's "Check your spelling" hit the primary problem: the entry point was spelled mian instead of main, so the linker never finds the program start. Additional issues visible in the snippets include use of old/non-standard headers, missing semicolons, end instead of endl, attempting arithmetic between a number and a string, and an identifier that starts with a digit.

A cleaned, minimal example that illustrates the fixes:

#include <iostream>
#include <string>

int main() {
    float x = 5.0f;
    std::string str = "Hello World!";
    std::cout << str << std::endl;
    std::cout << x << " " << str << std::endl;
    int num65 = 65;
    std::cout << "num65 = " << num65 << std::endl;
    return 0;
}

Notes and troubleshooting tips:

  • Prefer the standard headers <iostream> and <string>; the older *.h headers are pre-standard and often unsupported on modern compilers. string.h is the C header for C-style string functions — use <string> for std::string.
  • Identifiers cannot start with a digit (65Num is illegal). _65Num compiles but leading underscores at global scope are reserved for the implementation and should be avoided; use num65 or sixtyFive.
  • end is not a stream manipulator; use endl (or '\n' for performance). Multiplying a numeric type by a std::string is invalid — to concatenate for output, use multiple << operators or std::ostringstream.
  • Read compiler messages from top to bottom: fix the first error (often a missing semicolon or typo) then recompile. Enabling warnings (for example g++ -Wall -Wextra) reveals many common problems early.

's suggestion to add return 0; is fine — modern C++ treats falling off main as returning 0, but an explicit return 0; is clear and harmless.

Recommended Answers

All 4 Replies

Check your spelling...

...Ok.. I spotted the mistake now... Thanks for the hint.
I feel really stupid now... >_<

What about return 0?

[edit]
nvm....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.