Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 04-03-08   #1 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: oklahoma
Posts: 907

Rep: 44 Pooping^fish is acknowledged by some
Unique Rep: 40
Trader Rating: 2
Default Variable type allowing spaces?

Well, I got my app to write the title to the file.
Now my problem is it doesnt allow spaces. When it asks say Ill answer an ex. of "My answer". The only thing to be wrritten to file would be "My".
Im using string for the data types.

Heres my code:

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

using namespace std; 

int main()
{
   
   char filename[51]; //variable to store file name //declares an array of characters to store the file name, 50 chars long. 
  ofstream the_file; //variable to refer to stream to write to file

   cout <<"What do you want the name of your webpage to be? NOT the title!";
   cin  >> filename;
    the_file.open(filename);
string titlea = ("<title>");
string titleb = ("</title>");
    
   cout <<"What do you want the title to be?";
   string title;
   cin >> title;
   the_file <<titlea<<title<<titleb;
   the_file.close();
   cout << "nnnProgram by Fr0nAtZ!n";
   system("PAUSE");
   return 0;
}
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: CSS Pwner
CPU
e6400 @ 3.2
Motherboard
p5n-t 780i
Memory
2gb ocz @ 900
Graphics Card
8800gtx
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
Arch Linux, XP for games
Monitor
24" Westy

Last edited by Pooping^fish : 04-03-08 at 11:36 PM.
Pooping^fish is offline   Reply With Quote
Old 04-03-08   #2 (permalink)
I provide....LEVERAGE!
 
afzsom's Avatar
 
intel nvidia

Join Date: Jun 2007
Location: Boca, FL
Posts: 4,489

Rep: 609 afzsom is becoming famousafzsom is becoming famousafzsom is becoming famousafzsom is becoming famousafzsom is becoming famousafzsom is becoming famous
Unique Rep: 366
Trader Rating: 8
Default

Because you need to set the title as an array of chars (which includes spaces) like you did earlier in the program.
__________________
Watercooling Loop: MCP655 Vario -> Black Ice GTX360 -> D-Tek FuZion V1 -> MCW-60 -> MicroRes
Loop Cost: $395.03


System: R'lyeh
CPU
E6600 (L631F) @ 3.6GHz 1.425v (lapped)
Motherboard
Gigabyte EP45-UD3P (F7A)
Memory
4GB (2x2) Corsair Dominator (5-5-5-15, 2.1v)
Graphics Card
BFG Tech 8800GTS OC 640MB
Hard Drive
300GB WD VelociRaptor, 320GB WD Caviar 7200
Sound Card
Audigy 4
Power Supply
SeaSonic S12 550W
Case
Lian-Li V2000
CPU cooling
D-TEK FuZion V1
GPU cooling
MCW60
OS
Windows XP Professional SP3
Monitor
Samsung 226BW
afzsom is offline Overclocked Account afzsom's Gallery   Reply With Quote
Old 04-03-08   #3 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: oklahoma
Posts: 907

Rep: 44 Pooping^fish is acknowledged by some
Unique Rep: 40
Trader Rating: 2
Default

you mean char? I tried, it didnt the same thing.
Ill try agian just incanse..
Edit-Nope.
Char does the same thing, my filename wont take spaces either.
go figure.
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: CSS Pwner
CPU
e6400 @ 3.2
Motherboard
p5n-t 780i
Memory
2gb ocz @ 900
Graphics Card
8800gtx
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
Arch Linux, XP for games
Monitor
24" Westy
Pooping^fish is offline   Reply With Quote
Old 04-04-08   #4 (permalink)
Chiefly Ignorant
 
Scriptorum's Avatar
 
intel nvidia

Join Date: Jan 2008
Location: Atlanta, GA
Posts: 54
Blog Entries: 12

Rep: 13 Scriptorum Unknown
Unique Rep: 10
Trader Rating: 0
Default

I think the cin operator>> uses all whitespace as a string terminator. You could try cin.getline() instead. Or you could mess around with the noskipws manipulator to turn off this whitespace terminating "feature." Try putting this before the filename gets input:

Code:
cin >> noskipws;
Personally, I hate operator overloading. Anything that changes the grammar of a language is sure to confuse people more than necessary.
__________________
Quote:
Originally Posted by The Bartender Paradox View Post
crazy?...nah. when you cool with a fire extinguisher then your crazy.

System: Flaming Moe's MacBook Pro
CPU
Core 2 Duo
Motherboard
MacBook Pro
Memory
4GB DDR2-667
Graphics Card
512Mb NVIDIA GeForce 8600M GT
Hard Drive
200Gb 7200RPM
OS
OSX 10.5.2 / XP Pro / Boot Camp + Parallels
Monitor
17" Matte 1920x1200
Scriptorum is offline Overclocked Account   Reply With Quote
Old 04-04-08   #5 (permalink)
Programmer
 
intel ati

Join Date: Aug 2006
Location: Moscow, ID
Posts: 160

Rep: 10 Safetydan Unknown
Unique Rep: 9
Folding Team Rank: 1404
Trader Rating: 1
Default

Yeah, a string or char[] should be able to store spaces just fine. The issue seems to be that your cin call is only reading until the space. As Scriptorium suggested try cin.getline() which by default will read until it hits a newline (return) character.
__________________
"He attacked everything in life with a mix of extraordinary genius and naive incompetence, and it was often difficult to tell which was which."
Douglas Adams

System: Monster v2
CPU
Q6600 G0
Motherboard
GA-P35-DS3L
Memory
2GB Crucial Ballistix
Graphics Card
Saphire Radeon x1900XTX
Hard Drive
WD 320GB
Sound Card
x-fi extreme music (modded)
Power Supply
OCZ 700W
Case
Gigabyte 3D aurora
CPU cooling
TR Ultra-120 Extreme
GPU cooling
vf900
OS
Windows XP
Monitor
2x Acer 22" WS
Safetydan is offline I fold for Overclock.net   Reply With Quote
Old 04-04-08   #6 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: oklahoma
Posts: 907

Rep: 44 Pooping^fish is acknowledged by some
Unique Rep: 40
Trader Rating: 2
Default

when I use cin.getline(title,21) the programs compiles, but it just skips right past the title question. It says it but acts like ive already answers and the program terminates.
I tried the noskipws's, it did the same. I tried combining them like cin >> noskipws >> titie;
and I even tried cin >> noskipws; cin.getline(title,21); together. All did the same thing with skipping the title line.
Shouldnt this be really simple? ahhhh.
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: CSS Pwner
CPU
e6400 @ 3.2
Motherboard
p5n-t 780i
Memory
2gb ocz @ 900
Graphics Card
8800gtx
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
Arch Linux, XP for games
Monitor
24" Westy
Pooping^fish is offline   Reply With Quote
Old 04-04-08   #7 (permalink)
I provide....LEVERAGE!
 
afzsom's Avatar
 
intel nvidia

Join Date: Jun 2007
Location: Boca, FL
Posts: 4,489

Rep: 609 afzsom is becoming famousafzsom is becoming famousafzsom is becoming famousafzsom is becoming famousafzsom is becoming famousafzsom is becoming famous
Unique Rep: 366
Trader Rating: 8
Default

Try adding this line right after the initial cin >> filename;

Code:
cin.ignore();
What this does is capture the "carriage return/enter key" from entering in the file name. As it stands now the enter key (aka whitespace) is becoming the "title" instead of being ignored as it should be.
__________________
Watercooling Loop: MCP655 Vario -> Black Ice GTX360 -> D-Tek FuZion V1 -> MCW-60 -> MicroRes
Loop Cost: $395.03


System: R'lyeh
CPU
E6600 (L631F) @ 3.6GHz 1.425v (lapped)
Motherboard
Gigabyte EP45-UD3P (F7A)
Memory
4GB (2x2) Corsair Dominator (5-5-5-15, 2.1v)
Graphics Card
BFG Tech 8800GTS OC 640MB
Hard Drive
300GB WD VelociRaptor, 320GB WD Caviar 7200
Sound Card
Audigy 4
Power Supply
SeaSonic S12 550W
Case
Lian-Li V2000
CPU cooling
D-TEK FuZion V1
GPU cooling
MCW60
OS
Windows XP Professional SP3
Monitor
Samsung 226BW
afzsom is offline Overclocked Account afzsom's Gallery   Reply With Quote
Old 04-05-08   #8 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: oklahoma
Posts: 907

Rep: 44 Pooping^fish is acknowledged by some
Unique Rep: 40
Trader Rating: 2
Default

Nope. Epic fail once again. Does the same thing.
Have I generated some inter-space C++ time paradox of the white space people?
Perhaps I have.
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: CSS Pwner
CPU
e6400 @ 3.2
Motherboard
p5n-t 780i
Memory
2gb ocz @ 900
Graphics Card
8800gtx
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
Arch Linux, XP for games
Monitor
24" Westy
Pooping^fish is offline   Reply With Quote
Old 04-06-08   #9 (permalink)
Programmer
 
kdbolt70's Avatar
 
intel ati

Join Date: May 2007
Location: Walled Lake, MI
Posts: 1,119

Rep: 127 kdbolt70 is acknowledged by manykdbolt70 is acknowledged by many
Unique Rep: 92
Folding Team Rank: 284
Trader Rating: 1
Default

allright allright I'll give it a quick look, hang on.
__________________

~M Hail to the Victors M~

System: It's about time!
CPU
Q6600 G0 @3.3Ghz
Motherboard
Gigabyte P35-DS3L
Memory
2Gb Ballistix DDR2 800 @915Mhz
Graphics Card
Sapphire 2900Pro Flashed to XT
Hard Drive
Seagate Barracuda 320Gb
Sound Card
Onboard
Power Supply
Corsair HX 620W
Case
CM 690
CPU cooling
Tuniq Tower 120
GPU cooling
stock
OS
Vista Business and VMWare Ubuntu
Monitor
Acer AL2223W 22"
kdbolt70 is offline I fold for Overclock.net   Reply With Quote
Old 04-06-08   #10 (permalink)
Programmer
 
kdbolt70's Avatar
 
intel ati

Join Date: May 2007
Location: Walled Lake, MI
Posts: 1,119

Rep: 127 kdbolt70 is acknowledged by manykdbolt70 is acknowledged by many
Unique Rep: 92
Folding Team Rank: 284
Trader Rating: 1
Default

this seems to work:

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

using namespace std; 

int main()
{
   
   char filename[51]; //variable to store file name //declares an array of characters to store the file name, 50 chars long. 
  ofstream the_file; //variable to refer to stream to write to file

   cout <<"What do you want the name of your webpage to be? NOT the title!";
   cin.getline(filename, 50);
    the_file.open(filename);
string titlea = ("<title>");
string titleb = ("</title>");
    
   cout <<"What do you want the title to be?";
   char title[50];
   cin.getline(title, 50);
   the_file <<titlea<<title<<titleb;
   the_file.close();
   cout << "nnnProgram by Fr0nAtZ!n";
   system("PAUSE");
   return 0;
}
__________________

~M Hail to the Victors M~

System: It's about time!
CPU
Q6600 G0 @3.3Ghz
Motherboard
Gigabyte P35-DS3L
Memory
2Gb Ballistix DDR2 800 @915Mhz
Graphics Card
Sapphire 2900Pro Flashed to XT
Hard Drive
Seagate Barracuda 320Gb
Sound Card
Onboard
Power Supply
Corsair HX 620W
Case
CM 690
CPU cooling
Tuniq Tower 120
GPU cooling
stock
OS
Vista Business and VMWare Ubuntu
Monitor
Acer AL2223W 22"
kdbolt70 is offline I fold for Overclock.net   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 03:55 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.39839 seconds with 8 queries