Skip to content

Created term entry for .assign() method for C++ strings #7108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

em07-adoz
Copy link

Description

I created a term entry for the C++ strings .assign() method. My motivation for doing this was a a part of the my project for the Write Tech Bootcamp that I took to learn Technical Writing .

Issue Solved

Closes #7094 [Term Entry] C++ Strings: assign()

Type of Change

  • Adding a new entry
  • Adding a new entry
  • Editing an existing entry (fixing a typo, bug, issues, etc)
  • Updating the documentation

Checklist

  • [ x] All writings are my own.
  • [ x] My entry follows the Codecademy Docs style guide.
  • [ x] My changes generate no new warnings.
  • [x ] I have performed a self-review of my own writing and code.
  • [ x] I have checked my entry and corrected any misspellings.
  • [ x] I have made corresponding changes to the documentation if needed.
  • [ x] I have confirmed my changes are not being pushed from my forked main branch.
  • [x ] I have confirmed that I'm pushing from a new branch named after the changes I'm making.
  • [x ] I have linked any issues that are relevant to this PR in the Issues Solved section.

@mamtawardhani mamtawardhani self-assigned this Jun 15, 2025
@mamtawardhani mamtawardhani added c++ C++ entries new entry New entry or entries status: under review Issue or PR is currently being reviewed labels Jun 15, 2025
Copy link
Collaborator

@mamtawardhani mamtawardhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @em07-adoz, looks like the entry is jumbled up. The syntax section is apperaing in all the examples. Could you structure it please, then we can continue reviewing the entry. Can you also please fix the path of the file?

Thank you! 😄

Comment on lines +2 to +14
Title: '.assign()'
Description: 'Replaces the contents of a C++ string with new characters or strings.'
Subjects:
- 'Code Foundations'
- 'Computer Science'
Tags:
- 'Characters'
- 'Assignment'
- 'Methods'
- 'Strings'
CatalogContent:
- 'learn-c++'
- 'paths/computer-science'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Title: '.assign()'
Description: 'Replaces the contents of a C++ string with new characters or strings.'
Subjects:
- 'Code Foundations'
- 'Computer Science'
Tags:
- 'Characters'
- 'Assignment'
- 'Methods'
- 'Strings'
CatalogContent:
- 'learn-c++'
- 'paths/computer-science'
Title: '.assign()'
Description: 'Assigns new content to a string, replacing its current contents with specified characters, substrings, or values.'
Subjects:
- 'Code Foundations'
- 'Computer Science'
Tags:
- 'Assignment'
- 'Characters'
- 'Methods'
- 'Strings'
CatalogContent:
- 'learn-c-plus-plus'
- 'paths/computer-science'

Comment on lines +17 to +21
**`.assign()`** is a method used to **replace the contents of a C++ string** with new data. Unlike `.append()`, which adds to the end of a string, `.assign()` **overwrites** the current content.

This method is useful when:
- You want to fully replace a string with a different one.
- You need to copy a **substring**, specific **number of characters**, or even **characters from an iterator range**.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**`.assign()`** is a method used to **replace the contents of a C++ string** with new data. Unlike `.append()`, which adds to the end of a string, `.assign()` **overwrites** the current content.
This method is useful when:
- You want to fully replace a string with a different one.
- You need to copy a **substring**, specific **number of characters**, or even **characters from an iterator range**.
The **`.assign()`** method replaces the contents of a string with new characters, allowing precise control over what the string holds. It is commonly used in scenarios such as loops, input parsing, or reusing string variables to optimize memory and performance.

- You need to copy a **substring**, specific **number of characters**, or even **characters from an iterator range**.

---

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please showcase the Syntax of this term along with its parameter description and return value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Term Entry] C++ Strings: assign()
2 participants