Cramster.com - Homework Solutions, Lecture Notes, Exams, and Free Online Homework Help
Sign Up Now! Login Customer Support Cramster Blog
McAfee Secure sites help keep you safe from identity theft, credit card fraud, spyware, spam, viruses and online scams
Problem Solved.
    Home    
    Homework Help    
   Answer Board   
    Resources (Beta)    
   
Member's Topic Headline:

Help me to clear string i c/c++

Know the answer? Have a better solution? Share it.
Get Help Now.
View homework problems
explained for free!
Member Testimonials

Question:

Advertisement:

Answer | Ask New Question | Customize Profile | Leaderboards | 
FAQ

Member's Avatar

Rookie
Karma Points: 0
Respect (75%):
Date Posted: 7/24/2008 1:10:57 AM  Status: Live
Help me to clear string i c/c++
Course Textbook Chapter Problem
Software Design C++: How to Program (5th) by Deitel, Deitel, Deitel N/A N/A
Question Details:
Dear seniours
Please guide me about the header file <string.h>
and the keyword string
is it the replacement for defining the character array
and where we use it
give me appropriate e.g.
please reply soon as possibe
Thankx

Answers:

Member's Avatar

Guru
Karma Points: 2,019
Date Posted: 7/24/2008 1:52:47 AM  Status: Live
Asker's Rating: Lifesaver   
Response:

The <string.h> Header File

This is the ISO C standard header file for string and memory manipulation. This includes ascii strings and memory strings. Not yet all the standard functions of this header file are supported. If a declaration is present in the supplied header file, then uCR supports it and will continue to support it. If a function is not there, it will be added in time.

This header file defines several functions to manipulate C strings and arrays.
 
Concatenation:
strcat Concatenate strings (function)
strncat Append characters from string (function)

Comparison:
memcmp Compare two blocks of memory (function)
strcmp Compare two strings (function)
strcoll Compare two strings using locale (function)
strncmp Compare characters of two strings (function)
strxfrm Transform string using locale (function)

Searching:
memchr Locate character in block of memory (function)
strchr Locate first occurrence of character in string (function)
strcspn Get span until character in string (function)
strpbrk Locate character in string (function)
strrchr Locate last occurrence of character in string (function)
strspn Get span of character set in string (function)
strstr Locate substring (function)
strtok Split string into tokens (function)

Other:
memset Fill block of memory (function)
strerror Get pointer to error message string (function)
strlen Get string length (function)

 
STRING:
 
One of the most useful data types supplied in the C++ libraries is the string. A string is a variable that stores a sequence of letters or other characters, such as "Hello" or "May 10th is my birthday!". Just like the other data types, to create a string we first declare it, then we can store a value in it. Strings in C++ are fairly similar to strings in Java, but there are also some important differences. Below, we provide a brief overview of using strings in C++.

We can declare strings and assign literal values to them as follows:
 
string testString;
testString = "This is a string.";

We can combine these two statements into one line:
string testString = "This is a string.";

Often, we use strings as output, and
cout works exactly like one would expect:
 
cout << testString << endl;
 
will print the same result as

cout << "This is a string." << endl;
In order to use the string data type, the C++ string header file must be included at the top of the program. Also, you’ll need to include genlib.h to make the short name string visible instead of requiring the cumbersome std::string. (As a side note, std is a C++ namespace for many pieces of functionality that are provided in standard C++ libraries. For the purposes of this class, you won't need to know about namespaces.) Thus, you would have the following
 
#include's in your program in order to use the string type.
 
Example:
 
#include <iostream>
#include <string>
using namespace std;

int main ()
{
    char *line = "short line for testing";
   
    // with no arguments
    string s1;
    s1 = "Anatoliy";
    cout << "s1  is: " << s1 << endl;

    // copy constructor
    string s2 (s1);
    cout << "s2  is: " << s2 << endl;

    // one argumen
    string s3 (line);
    cout << "s3  is: " << s3 << endl;

    // first argumen C string
    // second number of characters
    string s4 (line,10);
    cout << "s4  is: " << s4 << endl;

    // 1 - C++ string
    // 2 - start position
    // 3 - number of characters
    string s5 (s3,6,4); // copy word 'line' from s3
    cout << "s5  is: " << s5 << endl;

    // 1 - number characters
    // 2 - character itself
    string s6 (15,'*');
    cout << "s6  is: " << s6 << endl;

    // 1 - start iterator
    // 2 - end iterator
    string s7 (s3.begin(),s3.end()-5);
    cout << "s7  is: " << s7 << endl;

    // you can instantiate string with assignment
    string s8 = "Anatoliy";
    cout << "s8  is: " << s8 << endl;

    return 0;
}

akmal_crazy's Comment:
Thanks for the annwer now i m sure i can clear my concepts about strings

Hope this will help you,
Don't forget to LIFE SAVER RATE to my answer plz.

Ziaxp (MIT)




By reading or posting messages on these forums, you are agreeing to the Answer Board's Terms of Service and Conduct (TSC).


About Cramster | Terms of Use | Privacy Policy | Contact Us | Press Room | Site Map | Support | Anti-Cheating Policy

Cramster.com is not affiliated with any publisher. Book covers, title and author names appear for reference only.
Copyright © 2008 Cramster, Inc.