Day 1: Hello World program

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:
yes, but in all fairness, he said something about "if" the prior line had the tabs, add the tabs to the next line. so shouldn't there be an If statement in there ? :)

Yeah. "If" I see a tab on the previous line I'll add that many tabs and add one more :p
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back