I\'m trying to learn about string
s, but different sources tell my to include different headers.
Some say to use
, but other
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.
Use this:
#include < string>
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.
Maybe this link will help you.
See: std::string documentation.
#include <string>
is the most widely accepted.
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
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;