A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/cpp_standard_library/cpp_string_clear.htm below:

C++ String Clear Function

C++ String Library - clear Description

It erases the contents of the string, which becomes an empty string.

Declaration

Following is the declaration for std::string::clear.

void clear();
C++11
void clear() noexcept;
Parameters

none

Return Value

none

Exceptions

if an exception is thrown, there are no changes in the string.

Example

In below example for std::string::clear.

#include <iostream>
#include <string>

int main () {
   char c;
   std::string str;
   std::cout << "Please type some lines of text. Enter a start (*) to finish:\n";
   do {
      c = std::cin.get();
      str += c;
      if (c=='\n') {
         std::cout << str;
         str.clear();
      }
   } while (c!='*');
   return 0;
}

The sample output should be like this −

Please type some lines of text. Enter a start (*) to finish:
sairam.krishna *

string.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4