Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1C++ String clear Empty C++ String clear Wed Jan 12, 2011 1:59 am

des

des
Achiever
Loading
void clear();
What does it do? The string content is set to an empty string, erasing any previous content and thus leaving its size at 0 characters.
Quick example:
Code:
// string::clear
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  string str;
  char c;
  cout << "Please type some lines of text. Enter a period to finish:\n";
  do {
    c=cin.get();
    str += c;
    if (c=='\n')
    {
      cout << str;
      str.clear();
    }
  } while (c!='.');
  return 0;
This program repeats every line introduced by the user until a period character ('.') is introduced. Every newline character ('\n') triggers the repetition of the line and the clearing of the current string content.
Basic template member declaration
( basic_string<charT,traits,Allocator> )
void clear ( );

2C++ String clear Empty Re: C++ String clear Wed Jan 12, 2011 3:24 am

DJ Fresh

DJ Fresh
Master
Loading
Thanks bro.

View previous topic View next topic Back to top  Message [Page 1 of 1]

Related topics

Permissions in this forum:
You cannot reply to topics in this forum