albybum
Penguin Rancher
- Joined
- 9 Feb 2002
- Messages
- 281
Code:
[SIZE=2][COLOR=#008000]//=================================================[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]// Author : Albert Holtsclaw[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]// Web : http://www.albybum.net[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]// Purpose: Hello World Program[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]// Lang : C++[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]//=================================================[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][COLOR=#800000]<iostream>[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][COLOR=#800000]<string>[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2][COLOR=#800000]<conio.h>[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] std::cout;[/SIZE]
[SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] std::string;[/SIZE]
[SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] main([/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]string strHello,[/SIZE]
[SIZE=2]strOSNN,[/SIZE]
[SIZE=2]strTab;[/SIZE]
[SIZE=2]strHello = [/SIZE][SIZE=2][COLOR=#800000]"Hello World!"[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]strOSNN = [/SIZE][SIZE=2][COLOR=#800000]"OSNN.net rules my world!"[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]strTab = [/SIZE][SIZE=2][COLOR=#800000]" "[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] nTabs = 1; [/SIZE]
[SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] nIndex = 0;[/SIZE]
[SIZE=2]cout << strHello << [/SIZE][SIZE=2][COLOR=#800000]"\n"[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]cout << strOSNN << [/SIZE][SIZE=2][COLOR=#800000]"\n"[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2](!strOSNN.empty()) [/SIZE][SIZE=2][COLOR=#008000]// while string contents not empty[/COLOR][/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#008000]// print tabs[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] nI=0;nI<nTabs;nI++)[/SIZE]
[SIZE=2]cout << strTab;[/SIZE]
[SIZE=2]nIndex = strOSNN.find_first_of([/SIZE][SIZE=2][COLOR=#800000]' '[/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2](nIndex>0) [/SIZE][SIZE=2][COLOR=#008000]// if there was a space[/COLOR][/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]cout << strOSNN.substr(0,nIndex) << [/SIZE][SIZE=2][COLOR=#800000]"\n"[/COLOR][/SIZE][SIZE=2]; [/SIZE][SIZE=2][COLOR=#008000]// print from first of string to space[/COLOR][/SIZE]
[SIZE=2]strOSNN.erase(0,nIndex+1); [/SIZE][SIZE=2][COLOR=#008000]// remove from first of string to position beyond space[/COLOR][/SIZE]
[SIZE=2]nTabs++; [/SIZE][SIZE=2][COLOR=#008000]// increase tab count[/COLOR][/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][SIZE=2][COLOR=#008000]// if there was not a space[/COLOR][/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]cout << strOSNN << [/SIZE][SIZE=2][COLOR=#800000]"\n"[/COLOR][/SIZE][SIZE=2]; [/SIZE][SIZE=2][COLOR=#008000]// print what we have left [/COLOR][/SIZE]
[SIZE=2]strOSNN.erase(0,strOSNN.length()); [/SIZE][SIZE=2][COLOR=#008000]// erase remainder of string, if any[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]_getch(); [/SIZE][SIZE=2][COLOR=#008000]// pause for input[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] 0;[/SIZE]
[SIZE=2]}[/SIZE]
Last edited: