I got this code from MSDN for a FAQ for Visual C++ 4.2
I saw this code, ran my eyes over it and I am wondering if the code is legal, according to the standard.
Code:
//piglatin.cpp
#include <string>
#include <iostream>
//convert a string to piglatin
string piglatin(const string& s)
{
string s1 ;
string s2(" .,;:?") ; //word separators
//word boundary markers
size_t start, end, next, p0 ;
int done = 0 ;
start = end = next = 0 ;
while (!done)
{
// Find start of word.
start = s.find_first_not_of(s2, next) ;
// Find end of word.
// Check for end of string.
p0 = s.find_first_of(s2, start) ;
end = (p0 >= s.length()) ? s.length() : p0 - 1 ;
// Copy all the word separators.
s1 = s1 + s.substr(next, start - next) ;
// Convert word to piglatin.
s1 = s1 + s.substr(start + 1, end - start) + s[start] + "ay" ;
next = end + 1;
// Check for end of string.
if( next >= s.length())
done = 1 ;
}
return s1 ;
}
void main()
{
string s("she sells sea shells by the sea shore") ;
cout << "s = " << s << endl ;
cout << "\npiglatin(s) = " << piglatin(s) << "\n"<< endl;
}
you know, even in the recent VC++ tutorial, they still used void main()...
no wonder windows has so many problems.
note: haven't tried compiling yet but I know it will compile...
Shouldn't it say
Code:
using namespace std;
under the includes...
also, i really think void should be changed to int (on main) and a return 0; added to the bottom. OR AT LEAST
__asm mov eax, 0x0
right?
-LC