473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

help with Borland C++ V.4.52

I could not get this program to run in Borland C++ V.4.52.
Error message: "size is not member of string in function main()"
However, this program run fine on g++.
Thanks for any help !
################################################## #####
#include <iostream.h>
#include <string.h>
#include <cstring.h>

int main()
{
cout << "Please enter your first name: ";
string name;
cin >> name;

// build the message that we intend to write
const string greeting = "Hello, " + name + "!";

// build the second and fourth lines of the output
const string spaces(greeting.size(), ' ');
const string second = "* " + spaces + " *";

// build the first and fifth lines of the output
const string first(second.size(), '*');

// write it all
cout << std::endl;
cout << first << std::endl;
cout << second << std::endl;
cout << "* " << greeting << " *" << std::endl;
cout << second << std::endl;
cout << first << std::endl;

return 0;
}

Oct 28 '05 #1
2 1866
tv****@hotmail.com wrote:
I could not get this program to run in Borland C++ V.4.52.
Error message: "size is not member of string in function main()"
However, this program run fine on g++.
Thanks for any help !
################################################## #####
#include <iostream.h>
#include <string.h>
Non standard.

# include <iostream>
# include <string>
From now on, all the names from the standard library are in namespace std. For example,

cout << "hey";

should be replaced by

std::cout << "hey";
#include <cstring.h>
Does not exists. It's either <string.h> or <cstring>. Note that both
are different from <string>.
int main()
{
cout << "Please enter your first name: ";
string name;
cin >> name;

// build the message that we intend to write
const string greeting = "Hello, " + name + "!";
To build strings, you should use std::ostringstream.

# include <sstream>

std::ostringstream oss;
oss << "Hello, " << name << "!";
std::cout << oss.str();
// build the second and fourth lines of the output
const string spaces(greeting.size(), ' ');
const string second = "* " + spaces + " *";

// build the first and fifth lines of the output
const string first(second.size(), '*');

// write it all
cout << std::endl;
cout << first << std::endl;
cout << second << std::endl;
cout << "* " << greeting << " *" << std::endl;
cout << second << std::endl;
cout << first << std::endl;
return 0;
}

Jonathan

Oct 28 '05 #2
tv****@hotmail.com wrote:
I could not get this program to run in Borland C++ V.4.52.
Error message: "size is not member of string in function main()"
However, this program run fine on g++.
Thanks for any help !


Try length() instead of size(). size() was added to string later (for
compatibility with other STL containers) and a very, very old compiler
might not have string::size().

john
Oct 28 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Marcin Borkowski | last post by:
Hello I need some small help in the Borland C++ Builder. I need to do something with string in format like "var1|var2|var3|var4|" and add it to some ComboBox (Items -> Add("var1"), Items ->...
1
by: patrick | last post by:
beginner trying to compile this simple program in Vide with bcc32 compiler. I get this when I try to build. ! Error: Unresolved external 'WinMain' referenced from...
2
by: digitalfish | last post by:
I have two related tables in my SQL database that I wish to join as follows: ------------------------------------ tblCustomers ID (pk) Name etc. tblCustomerManagers
0
by: Kenneth Gomez | last post by:
Hello, I have tried many avenues (web search, borland website, libxml website) before deciding to post here. I'm trying to install libxml2 on windows ME to work with my Borland C++ 5 Compiler...
3
by: glenn | last post by:
Can anyone tell me what resource you use to get help with C# VS? or VS in general? I have been programming in Delphi for 10 years and am just getting started with VS and I have to say that the...
6
by: Dr Ann Huxtable | last post by:
Hi All, I am trying to compile an old C code written for the Borland Compiler on the DOS platform. This is a tactical solution and I intend to rip out the GUI side of things and slap on...
22
by: smartwolf agassi via DotNetMonster.com | last post by:
I'm a C# language learner. I want to know which IDE is better for C# programing, Borland C#Builder or VS.net 2003? -- Message posted via http://www.dotnetmonster.com
4
by: darrensjunkaccount | last post by:
Hi, I have just inherited some embedded software that was compiled with Borland 4.52. I need to either purchase that compiler, which Borland no longer appear to sell or alternatively source an...
1
by: dhruba.bandopadhyay | last post by:
Am wondering whether Borland C++ 4.5 or Borland Turbo C++ 1.01 supported C++ templates. If not, which other future version of BC++ or TC++ did? If BC++ 4.5 or TC++ 1.01 does support it, how much...
1
by: khalifa24 | last post by:
Hi: I am posting this for a colleague and would appreicate any feedback on this! Thanks, Yasir ----------------- I am collecting data from an A/D card that I have programmed using Borland...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.