New Posts  All Forums:Forum Nav:

cin.getline being skipped?

post #1 of 4
Thread Starter 
New problem now! Fuapa and dee de dee! I wrote basically all or most of my program and so far so good..buttt one random line where it cin's "body" gets skipped. It asks the question and skips to the next question. Frustrated, it produces no errors.. Ideas?

Code:
#include <string>
#include <iostream>
#include <fstream>

using namespace std; 

int main()
{
   char filename[51]; //filename to be stored
   char title[51]; //page title
   char body[301]; //body text
   char comments[75]; //extra raw code input
   ofstream the_file;

   cout <<"What do you want the name of your webpage to be? NOT the title! Dont forget to add the .html extension! \
"; 
   cin.getline(filename, 50, '\
');
   the_file.open(filename);
   
   
   the_file << "<html>"; //start html code
   
   string titlea = ("<title>");
   string titleb = ("</title>");
    
   cout <<"What do you want the title to be? \
"; //page title
   cin.getline(title, 50, '\
');
   the_file << titlea << title << titleb; //write page tags and title
   
   cout <<"What color do you want the background to be? Generic colors. You can also use an image in the same directory or specify an image in another directory. \
";
   string bg1 = ("<body bgcolor=");
   string bg2 = (">");
   string bg;
   cin >> bg;
   the_file << bg1<< bg<< bg2; //write body color tags and color
   
  
   cout <<"What do you want the body text of your page to be?"; //take in body text..cout is presented but getline is skipped so there is no input. Ehh?
   cin.getline(body, 300, '\
');
   
   cout <<"Do you want your text centered? 'yes' or 'no'. \
"; //Whether to center body text or not. Check over soon and clean.
   string align;
   cin >> align;
    if    (align == "yes") //center
    
    { 
   string body1 = ("<body>");
   string body2 = ("</body>");
   string div1 = ("<div align=center>");
   string div2 = ("</div>");
   
   the_file << div1 << body1;
   the_file << body;
   the_file << div2 << body2;
   }
   
   if (align == "no"); //dont center
   {
   string body1 = ("<body>");
   string body2 = ("</body>");
   the_file << body1 << body <<body2;       
   }
   
   cout <<"What do you want your text color to be? If none specified it will be black. \
";
   string textcolor;
   string text1 = ("<font color=");
   string text3 = ("</font>");
   string text2 = (">");
   cin >> textcolor;
   the_file << text1 << textcolor << text2 << text3;
   
   
   cout <<"If there is any other html comments or RAW CODE you can enter it here: "; //Question again presented but skips input. Why?
   cin.getline(comments, 74, '\
');
   the_file << comments;
   
   
   the_file << "</html>"; //finish off html tags
   
   

   
   
   
   the_file.close();
   cout << "\
\
\
Program by Fr0nAtZ!\
"; //ohhaimehellothar
   system("PAUSE");
   return 0;
}
I need to figure out why the body line and the comments line are being skipped.
I have the spaces problem fixed and write problem fixed of course.

Thanks all!
ragequit
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9550 4ghz @ 1.25v Asus Max 2 formula 8800gtx 610/1ghz OCZ LV blade 1:1 950mhz 
Hard DriveOptical DriveOSMonitor
7200.10 250gb dvd leetlinucks 24" Westy 
KeyboardPowerCaseMouse
G15 750w Toughpower Lian li pc-65 Copperhead 
Mouse Pad
Thermtaltake? 
  hide details  
Reply
ragequit
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9550 4ghz @ 1.25v Asus Max 2 formula 8800gtx 610/1ghz OCZ LV blade 1:1 950mhz 
Hard DriveOptical DriveOSMonitor
7200.10 250gb dvd leetlinucks 24" Westy 
KeyboardPowerCaseMouse
G15 750w Toughpower Lian li pc-65 Copperhead 
Mouse Pad
Thermtaltake? 
  hide details  
Reply
post #2 of 4
Oh wait nevermind... I see what your saying... *edit*


You will need to clear your stream. Take a look at cin.clear() and cin.ignore().

The reason your code doesn't stop at the body and comments sections is because you still have your control characters in the cin buffer. Your newline char isn't getting cleared from your << call.

getline() removes the newline control character. << does not remove it.
GAMR
(15 items)
 
  
CPUMotherboardGraphicsGraphics
6600K ASUS Z170-A ASUS 970 Strix ASUS 970 Strix 
RAMHard DriveHard DriveHard Drive
Crucial Ballistix Elite Samsung 850 EVO Intel 320 6400AAKS 
Hard DriveCoolingMonitorPower
6400AAKS Cooler Master Hyper 212 EVO ASUS VG24QE EVGA SuperNova 650 G2 
CaseMouseMouse Pad
Antec 1200 Razer Abyssus 3.5G QCK+ 
  hide details  
Reply
GAMR
(15 items)
 
  
CPUMotherboardGraphicsGraphics
6600K ASUS Z170-A ASUS 970 Strix ASUS 970 Strix 
RAMHard DriveHard DriveHard Drive
Crucial Ballistix Elite Samsung 850 EVO Intel 320 6400AAKS 
Hard DriveCoolingMonitorPower
6400AAKS Cooler Master Hyper 212 EVO ASUS VG24QE EVGA SuperNova 650 G2 
CaseMouseMouse Pad
Antec 1200 Razer Abyssus 3.5G QCK+ 
  hide details  
Reply
post #3 of 4
BTW, you should have only one body tag in your HTML document. All layout tags belong inside the body tag, not outside. For example:

Code:
<html>
   <head>
      ...all head tags go in here (title, etc)
   </head>
   <body bgcolor=xxxxx>
      ... ALL displayable content goes here
   </body>
</html>
    
CPUGraphicsRAMHard Drive
Intel 2.4 Core i7 AMD Radeon HD 6750M 8 GB 1067 MHz DDR3 750 GB 
OS
Mac OS-X Lion 
  hide details  
Reply
    
CPUGraphicsRAMHard Drive
Intel 2.4 Core i7 AMD Radeon HD 6750M 8 GB 1067 MHz DDR3 750 GB 
OS
Mac OS-X Lion 
  hide details  
Reply
post #4 of 4
Thread Starter 
Oh, really?
Weird. Well I got it finished with a lot of help from a friend. Lots of problems encountered during this.
ragequit
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9550 4ghz @ 1.25v Asus Max 2 formula 8800gtx 610/1ghz OCZ LV blade 1:1 950mhz 
Hard DriveOptical DriveOSMonitor
7200.10 250gb dvd leetlinucks 24" Westy 
KeyboardPowerCaseMouse
G15 750w Toughpower Lian li pc-65 Copperhead 
Mouse Pad
Thermtaltake? 
  hide details  
Reply
ragequit
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9550 4ghz @ 1.25v Asus Max 2 formula 8800gtx 610/1ghz OCZ LV blade 1:1 950mhz 
Hard DriveOptical DriveOSMonitor
7200.10 250gb dvd leetlinucks 24" Westy 
KeyboardPowerCaseMouse
G15 750w Toughpower Lian li pc-65 Copperhead 
Mouse Pad
Thermtaltake? 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming