Google Interview Question
Software Engineer / DevelopersTeam: codeblock
Country: India
Something like this? :)
#include <iostream>
#include <vector>
using namespace std;
class String
{
public:
String()
{}
String(char* inputCharacters)
{
const char endOfStringSign = '\0';
while(*inputCharacters != endOfStringSign)
{
characters.push_back(*inputCharacters);
inputCharacters++;
}
}
friend ostream& operator<<(ostream& outputStream, const String& string);
int len() const
{
return characters.size();
}
private:
vector<char> characters;
};
ostream& operator<<(ostream& outputStream, const String& string)
{
for(auto sign : string.characters)
{
outputStream << sign;
}
return outputStream;
}
int main()
{
String str1;
cout << str1.len() << "\n";
String str2("Luke I am your father!");
cout << str2 << "\n";
cout << str2.len() << "\n";
return 0;
}
Was this asked by Google? Seriously?
- Epic_coder October 26, 2012