Problem with Borland C++Builder X and program known to work
Results 1 to 3 of 3

Thread: Problem with Borland C++Builder X and program known to work

  1. #1
    The Prancing Pirate
    Join Date
    Jul 2004
    Posts
    548

    Problem with Borland C++Builder X and program known to work

    --My error - solved

    Hi,

    I am currently learning C++ from a book called Accelerated C++, whose website can be found here. I copied out the source code for producing a framed greeting message, and it is as follows:
    Code:
    //ask for a person's name, and generate a framed greeting
    #include <iostream>
    #include <string>
    
    int main()
    {
      std::cout << "Please enter your first name: ";
      std::string name;
      std::cin >> name;
    
      //build the message that we intend to write
      const std::string spaces(greeting.size(), ' ');
      const std::string second = "* " + spaces + " *";
    
      //build the first and fifth lines of the output
      const std::string first(second.size(), '*');
    
      //write it all
      std::cout << std::endl;
      std::cout << first << std::endl;
      std::cout << second << std::endl;
      std::cout << "* " << greeting << " *" << std::endl;
      std::cout << second << std::endl;
      std::cout << first << std::endl;
    
      return 0;
    }
    I then tried to compile it, but Borland said:
    "untitled1.cpp": E2451 Undefined symbol 'greeting' in function main() at line 12
    So, I thought there may be something wrong with my copied-out source code (I had checked the line mentioned against the line in the book and they were exactly the same). I downloaded the Borland sources for the programs in the book, and opened up their version of the program. It was exactly the same, and it also refused to compile, returning the same error. How can this be? The program MUST work, but my compiler denies this...Any help would be greatly appreciated, thanks in advance!

    edit: Just retried it and the Borland's source code does work... Here is Borland source:
    Code:
    // ask for a person's name, and generate a framed greeting
    #include <iostream>
    #include <string>
    
    int main()
    {
    	std::cout << "Please enter your first name: ";
    	std::string name;
    	std::cin >> name;
    
    	// build the message that we intend to write
    	const std::string greeting = "Hello, " + name + "!";
    
    	// build the second and fourth lines of the output
    	const std::string spaces(greeting.size(), ' ');
    	const std::string second = "* " + spaces + " *";
    
    	// build the first and fifth lines of the output
    	const std::string first(second.size(), '*');
    
    	// write it all
    	std::cout << std::endl;
    	std::cout << first << std::endl;
    	std::cout << second << std::endl;
    	std::cout << "* " << greeting << " *" << std::endl;
    	std::cout << second << std::endl;
    	std::cout << first << std::endl;
    
    	return 0;
    }
    I tried copying their "line 12" and putting it into my source code, but that didn't work...

    edit2: My mistake! So sorry everyone, I must've missed the following lines:
    Code:
    // build the message that we intend to write
    const std::string greeting = "Hello, " + name + "!";
    Sorry again!

    J_K9
    TAZForum <---- click

  2. #2
    Banned
    Join Date
    Jul 2005
    Posts
    511
    Nice! That's what we like to see here. People who are able to solve their own problems. Just shows that there are some smart people out there too.
    Then again, daring to ask a question is also a sign of intelligence. Too many people out there have a problem and never dare to ask someone else for help, because they fear it makes them look stupid. Not asking a question about something you can't solve by yourself, that would be dumb.

  3. #3
    The Prancing Pirate
    Join Date
    Jul 2004
    Posts
    548
    Thanks Katja (for the theory) Oh, and well done, 200+ greenies in less than 30 posts...Pretty impressive!

    J_K9
    TAZForum <---- click

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •