A
Arash_89
Guest
Hello,
What is the differences between Sizeof vs Length vs Capacity in C++?
In the below example:
Length() is 12.
Sizeof() is 28 and capacity is 15.
#include <iostream>
#include<string>
using namespace std;
int main()
{
string s;
getline(cin, s);
int sl = s.length();
int so = sizeof(s);
char* p = new char[sl];
for (int i = 0; i < sl; i++)
{
p = s;
}
for (int i = 0; i < sl; i++)
{
cout << p << " ";
}
return 0;
}
Continue reading...
What is the differences between Sizeof vs Length vs Capacity in C++?
In the below example:
Length() is 12.
Sizeof() is 28 and capacity is 15.
#include <iostream>
#include<string>
using namespace std;
int main()
{
string s;
getline(cin, s);
int sl = s.length();
int so = sizeof(s);
char* p = new char[sl];
for (int i = 0; i < sl; i++)
{
p = s;
}
for (int i = 0; i < sl; i++)
{
cout << p << " ";
}
return 0;
}
Continue reading...