How do I include the string header?

后端 未结 9 1131
旧时难觅i
旧时难觅i 2020-12-05 10:01

I\'m trying to learn about strings, but different sources tell my to include different headers.

Some say to use , but other

相关标签:
9条回答
  • 2020-12-05 10:02

    The C++ string class is std::string. To use it you need to include the <string> header.

    For the fundamentals of how to use std::string, you'll want to consult a good introductory C++ book.

    0 讨论(0)
  • 2020-12-05 10:03

    Use this:

    #include < string>
    
    0 讨论(0)
  • 2020-12-05 10:05

    You want to include <string> and use std::string:

    #include <string>
    #include <iostream>
    
    int main()
    {
        std::string s = "a string";
        std::cout << s << std::endl;
    }
    

    But what you really need to do is get an introductory level book. You aren't going to learn properly any other way, certainly not scrapping for information online.

    0 讨论(0)
  • 2020-12-05 10:05

    Maybe this link will help you.

    See: std::string documentation.

    #include <string> is the most widely accepted.

    0 讨论(0)
  • 2020-12-05 10:06

    I don't hear about "apstring".If you want to use string with c++ ,you can do like this:

    #include<string>
    using namespace std;
    int main()
    {
       string str;
       cin>>str;
       cout<<str;
       ...
       return 0;
    }
    

    I hope this can avail

    0 讨论(0)
  • 2020-12-05 10:06

    For using the string header first we must have include string header file as #include <string> and then we can include string header in the following ways in C++:

    1)

    string header = "--- Demonstrates Unformatted Input ---";
    

    2)

    string header("**** Counts words****\n"), prompt("Enter a text and terminate"
    " with a period and return:"), line( 60, '-'), text;
    
    0 讨论(0)
提交回复
热议问题