C++ Programming Help: Troubleshooting "<" to ".

  • Thread starter Tom McCurdy
  • Start date
  • Tags
    Programming
In summary, the conversation discusses a problem with a C++ code that is supposed to replace anything between < > with periods but instead changes everything in the string to periods. The expert points out that the error is due to using the assignment operator instead of the boolean operator in an "if" statement. They also mention that some of the code may be unnecessary and suggest checking the programming sub-forum for further assistance.
  • #1
Tom McCurdy
1,020
1
I am having trouble with this in C++
Code:
  while(k < bodyCopy.size())
    {
      bodyCopy[k] = tolower(bodyCopy[k]);
      please=bodyCopy[k];
      cout<<please<<endl;
      if (please='<')
      {
           inTag=1;
      }
      if (inTag==1)
      {
           please='.';
           bodyCopy[k]=please;
      }
              
      if (please=='>')
      {
           inTag=0;
      }         
                                 
      
      
      k = k + 1;
    }
Its supose to replace any thing in string body.Copy between < > with periods but leave everything else alone
currently it changes everything in body.Copy to periods
any idea why??
 
Technology news on Phys.org
  • #2
If it would help I would post my entire code but I have a feeling that might confuse more then help solve this problem
 
  • #3
cuz you need to use the boolean operator not the assignment operator in your "if" statement, very common mistake, i hate making that error.

also some of the code seems unnecessary unless that was your debugging technique.
 
  • #4
neurocomp2003 said:
cuz you need to use the boolean operator not the assignment operator in your "if" statement, very common mistake, i hate making that error.

also some of the code seems unnecessary unless that was your debugging technique.
Thank you for eyes...

I can't believe I missed that...

now only one problem left
 
  • #5
I guess you must not have noticed that the next forum down, "Computers", has a sub-forum named "Programming." :smile:
 

1. Why am I getting an error when trying to use the "<" symbol in place of "." in my C++ code?

This error is most likely occurring because the "<" symbol is used for comparison operations in C++, while the "." symbol is used for accessing elements or properties within a data structure. Make sure you are using the correct symbol for the intended operation.

2. How do I troubleshoot an issue with "<" and "." symbols in my C++ code?

To troubleshoot, start by carefully reviewing your code and checking for any typos or misplaced symbols. You can also use a debugger tool to step through your code and see where the issue is occurring. Additionally, researching the specific error message you are receiving can provide helpful insights.

3. Can I use the "<" symbol in place of "." in all situations in C++?

No, it is important to understand the specific purpose and usage of these symbols in C++. While they may have similar appearances, they serve different functions and should not be used interchangeably.

4. What other common errors are related to the use of "<" and "." in C++?

Some common errors related to these symbols include forgetting to include the necessary header files, using incorrect syntax for comparison or accessing elements, and attempting to use them in situations where they are not applicable (e.g. using "<" to compare strings instead of the correct "strcmp()" function).

5. Are there any resources or tools available to help with troubleshooting issues related to "<" and "." in C++?

Yes, there are many online forums, tutorials, and documentation available that can provide guidance on using these symbols correctly in C++. Additionally, using a debugger tool and researching specific error messages can also be helpful in troubleshooting.

Similar threads

  • Programming and Computer Science
Replies
12
Views
1K
Replies
10
Views
952
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
3
Replies
89
Views
4K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
3
Replies
75
Views
4K
  • Programming and Computer Science
Replies
19
Views
964
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
8
Views
2K
Back
Top