473,395 Members | 1,968 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,395 software developers and data experts.

Project

41
Hi,

I wrote a palindrome code in C++, and got a few errors that I can not figure it out. I'm suppose to write the palindrome program and "erase the spaces betweeen words".
Expand|Select|Wrap|Line Numbers
  1. *snip*
  2.  
The line in bold is the problem,

Thanks,

Doug
Mar 28 '07 #1
11 1567
sicarie
4,677 Expert Mod 4TB
There were four or fives lines bolded, can you post the one that you think is the problem, and how you know it's the problem (ie - the error message, or a description of what the output is doing that is incorrect)?
Mar 28 '07 #2
RedSon
5,000 Expert 4TB
If this is a homework question it should be treated as such. Is this palindrome code part of your assignment?
Mar 28 '07 #3
RedSon
5,000 Expert 4TB
Also dougg your thread title is unacceptable per the posting guidelines. Please read the FAQ located in the Tabs above and pay particular attention to http://www.thescripts.com/forum/faq....d_thread_title
Mar 28 '07 #4
d0ugg
41
Sorry for the title.
This is part of my hw, but i already included the code. I just need to know what is the error. I forgot to include the error message;
Here it goes:

c:\documentos\programas\palindrome\palindrome\pali ndrome\palindrome.cpp(77) : error C2228: left of '.length' must have class/struct/union
c:\documentos\programas\palindrome\palindrome\pali ndrome\palindrome.cpp(78) : error C2109: subscript requires array or pointer type
c:\documentos\programas\palindrome\palindrome\pali ndrome\palindrome.cpp(79) : error C2228: left of '.erase' must have class/struct/union

So those are the error messages, and here are the lines:

for (int i = 0; i < s.length(); i++)
if (s[i] == ' ')
s.erase(i, 1);

Thanks again
Mar 28 '07 #5
RedSon
5,000 Expert 4TB
No problem its just a warning so that you will be better prepared for the future. Also, please read the posting guidelines in the FAQ, for homework assignments we limit code to just the lines that are causing the problem. What you have copied above is fine.
Mar 28 '07 #6
RedSon
5,000 Expert 4TB
Sorry for the title.
This is part of my hw, but i already included the code. I just need to know what is the error. I forgot to include the error message;
Here it goes:

c:\documentos\programas\palindrome\palindrome\pali ndrome\palindrome.cpp(77) : error C2228: left of '.length' must have class/struct/union
c:\documentos\programas\palindrome\palindrome\pali ndrome\palindrome.cpp(78) : error C2109: subscript requires array or pointer type
c:\documentos\programas\palindrome\palindrome\pali ndrome\palindrome.cpp(79) : error C2228: left of '.erase' must have class/struct/union

So those are the error messages, and here are the lines:

for (int i = 0; i < s.length(); i++)
if (s[i] == ' ')
s.erase(i, 1);

Thanks again
Please give us the declaration for what s is. If its String s, then it should be String s = new String(); before you can start doing operations on it.
Mar 28 '07 #7
sicarie
4,677 Expert Mod 4TB
s was declared int.
Mar 28 '07 #8
d0ugg
41
s = space between words.

please let me know if you have any other question

doug
Mar 28 '07 #9
JosAH
11,448 Expert 8TB
No problem its just a warning
The compiler clearly did say "error" instead of "waring" in its diagnostic message
though.

kind regards,

Jos

ps. not surprising because that 's' identifier was defined to be of type int.
Mar 28 '07 #10
RedSon
5,000 Expert 4TB
The compiler clearly did say "error" instead of "waring" in its diagnostic message
though.

kind regards,

Jos

ps. not surprising because that 's' identifier was defined to be of type int.
Either you are trying to make a joke or you misunderstand me. I wasn't referring to the compiler problems.
Mar 28 '07 #11
RedSon
5,000 Expert 4TB
s was declared int.
if s is an int you cannot do things like s.length or s[i] those are undefined for type int.
Mar 28 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: public heath vb developer | last post by:
We have a solution with 29 projects including a main menu and 28 dlls. One of the projects (Project B) was created by copying an existing project (Project A), making changes including the assembly...
2
by: Rudy Ray Moore | last post by:
How can I modify the project build order of a multi-project workspace under "Visual Studio .net 2003 7.1 c++"? I tried to modify the .sln by hand to influence the build order, but it didn't seem...
1
by: Jerad Rose | last post by:
Hello, I have searched all over for the answer to this, to no avail. I have a web project already set up and running on a remote server, that I created from my home computer. I am now trying...
11
by: Dave | last post by:
I copied the project files from an ASP.NET project on one computer and want to create the project on another computer, There is no connection between the two computers so I simply copied the...
4
by: Brad | last post by:
I'm not one to rant or flame....so please excuse me while I do so for this once. I've now spent a bit of time working with VS2005 beta 2 to see how it functions for web development, especially how...
7
by: Mantorok | last post by:
Hi all We have an ASP.Net project (and the Solution) under source-control. Here is the example - I create the Solution, I create an ASP.Net project and then check it all in to source control,...
6
by: liu | last post by:
Hi all, in my vb.net solution, i have 3 project: 1. Main-this is the startup or the base of my window application. 2. Sales-this is the project that contains all the sales info 3. Product-this...
9
by: Anubhav Jain | last post by:
Hi, I am having few .net source files(.cs or .vb) and I want to dynamically generate the corresponding .net project file(.csproj or .vbproj) for them without using visual studio.So that I could...
3
by: Jerad Rose | last post by:
This is regarding Visual Studio 2003 (framework 1.1). We have several projects/libraries. Of course, many of these reference each other. If we only had one solution, we would simply add all of...
29
by: Tony Girgenti | last post by:
Hello. I'm developing and testing a web application using VS.NET 2003, VB, .NET Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1 on a WIN XP Pro, SP2 computer. I'm using a web form. How do I...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.