I have just started with a tutorial in c++ and i wonder if anyone can tell me what´s wrong with this code

#include <iostream>

using namespace std; //so the program can see cout and end1

int main()
{
        
          for  (int x = 0; x < 10; x++) {
              
               cout<< x <<end1;
               }
              cin.get();
}

Dani AI

Generated

This thread shows a classic beginner case: posted a short C++ example and it was fixed quickly by and . A few concise follow-up tips that help avoid similar traps and make debugging easier are listed below.

Always compile with warnings enabled so small mistakes surface immediately. A common g++ command is g++ -Wall -Wextra -std=c++17 file.cpp -o program; GCC documents its warning options at GCC warning options. Exact compiler output and the command line used are the most useful information when diagnosing problems.

Be aware that some I/O manipulators also cause a stream flush, which affects performance and observable behavior; pick the right manipulator when a flush is intended. See the standard description of std::endl for details: std::endl. The C++ language rules about the main function and its return behavior are documented here: .

For larger projects, avoid using namespace std in headers or shared code; prefer explicit std:: qualifiers for clarity and to prevent name collisions (namespace FAQ). For simple pauses during learning, running the program from a terminal or using the debugger is usually more robust than ad hoc input reads. Troubleshooting is fastest when exact compiler messages and the build command are included.

Recommended Answers

All 3 Replies

> and i wonder if anyone can tell me what´s wrong with this code
Posting error messages helps.

> end1;
In your case, I guess you mean endl
That's lower-case "L" (l) at the end, not numeric one(1).

that solved the problem, thaks

Use return 0; at the end of the program, otherwise compiler will throw warning.
Its a good programming practice.

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.