Question 6
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
#include <string_view>
int main() {
std::string_view url = "https://learnfrenzy.com/programming/cpp";
auto scheme = url.substr(0, url.find("://"));
url.remove_prefix(scheme.size() + 3);
auto host = url.substr(0, url.find('/'));
auto path = url.substr(host.size());
std::cout << scheme << '|' << host << '|' << path << '|' << path.size() << '\n';
return 0;
}
- A https|learnfrenzy.com|/programming/cpp|16 Correct
- B https|learnfrenzy.com|programming/cpp|15
- C https://|learnfrenzy.com|/programming/cpp|16
- D https|learnfrenzy|.com/programming/cpp|20
Correct Answer: Option A
substr and remove_prefix on a string_view only adjust a pointer and a length – the original characters are never copied.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!