The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsOk well i have this small problem. I delcare a file type with this line:
char filetype[255];
The I get a user input with the following line:
cin>>filetype;
Nothing new. Now here's the problem. I run filetype through this:
do
if((filetype != "vb")||(filetype != "cpp")){
error = true;
cout<<"...invalid file type!"<<endl;
cout<<"Visual Basic = vb"<<endl;
cout<<"C/C++ = cpp"<<endl;
cin>>filetype;
}
else
error = false;
while (error = true);
But no matter what i enter i get the ...invalid error message. I tryed couting out the result and i get whatever i entered, but what i look at the var in the watch, i get 0xfe23d [value i entered]. So i guess the first thing is the var addres or something. Anyone knows how to fix it?(sinnernaut don't say "iostream is the devil"....lol);P
iostream does suck. Admit it. Also, instead of char filetype[255]; it should be string filetype;
Also be sure to #include <string>
Then that code will work fine. There seems to be a misconception here about C++ style strings and C style strings.
There are some important differences:
With C style, you have to do if(strcmp(asdf,"varvalue") == 0)
With C++ style, you can do if(asdf == "varvalue");
Also, with C style you have to declare size so it knows how huge of a buffer to push onto The Stack, while with C++ style, the string class dynamically allocates memory for you and puts that shit on The Heap.
omg.
Playstation Network tag: muffin-noodle
the empty set
When i include <string> i get "string is an undeclared identifier whae i try to declare filetype. Any ideas?
#incluede <iostream>
#include<string.h>
string filetype;
cin>>filetype;
do
if((filetype != "vb")||(filetype != "cpp")){
error = true;
cout<<"...invalid file type! You entered ("<<filetype;<<")"<<endl;
cout<<"Visual Basic = vb"<<endl;
cout<<"C/C++ = cpp"<<endl;
cin>>filetype;
system("pause"); // Pause just in case
}
else
error = false;
while (error = true);
Try that, I'm not sure if it'll work, I just wrote it spur of the moment.
Post your full code cinjection, so we can see whats goin on. We`ll be of much more help if we saw everything.
At 5/20/05 10:34 PM, Pilot-Doofy wrote: code
Brilliant job on leaving out main(); and using whorey system(); functions.
:)
omg.
Playstation Network tag: muffin-noodle
the empty set
At 5/20/05 10:38 PM, Sinnernaut wrote: Brilliant job on leaving out main(); and using whorey system(); functions.
Sorry, I'm a bit high and c++ isn't my favorite to begin with. Lawl. ASK ME A PHP QUESTION YOU FUCKS!!!
add a { after the do command and a } before the while command. That might be your problem.
basic template
do
{
// Add commands here
// Yep...
} while ( statement );
At 5/20/05 06:30 PM, Cinjection wrote: Ok well i have this small problem. I delcare a file type with this line:
char filetype[255];
In C++, you don't need to declar char arrays, use the string header.
The I get a user input with the following line:
cin>>filetype;
Nothing new. Now here's the problem. I run filetype through this:
Don't you need cin.get() afterwards?
do
if((filetype != "vb")||(filetype != "cpp")){
error = true;
cout<<"...invalid file type!"<<endl;
cout<<"Visual Basic = vb"<<endl;
cout<<"C/C++ = cpp"<<endl;
cin>>filetype;
}
else
error = false;
while (error = true);
Also, this might be a typo, but what you want here is error == true, no?
But no matter what i enter i get the ...invalid error message. I tryed couting out the result and i get whatever i entered, but what i look at the var in the watch, i get 0xfe23d [value i entered]. So i guess the first thing is the var addres or something. Anyone knows how to fix it?(sinnernaut don't say "iostream is the devil"....lol);P
You're missing the main declaration and all the other stuff, so I don't know if there might be a problem somewhere else. Iostream works perfectly fine, though.
At 5/21/05 12:30 AM, ManateeGod-Sama wrote: Don't you need cin.get() afterwards?
No, you must be refering to cin.ignore(); which is the PERL equivalent of chomp(); and strips newline (I believe. I. Hate. IOStream. It's ridiculously bloated, and all the functions look like complete shit.
Really. They do.)
And if he WAS using cin.get(); he'd have to do fflush(stdin); beforehand so cin doesn't read shit clogging the input buffer.
omg.
Playstation Network tag: muffin-noodle
the empty set
filetype = "";
error = true;
do
{
if( ( !strcmp(filetype, "vb") ) || ( !strcmp(filetype, "cpp") ) )
{
cout<<"...invalid file type!"<<endl;
cout<<"Visual Basic = vb"<<endl;
cout<<"C/C++ = cpp"<<endl;
cin>>filetype;
}
else
error = false;
}
while (error == true);
try this.
you need {} on a do-while loop, and in the parameter in while, you were missing one =, so that would return true no matter what.
And you can use comparison operators on strings (char * is just an address, so you would be comparing addresses, use strcmp (returns 0 if the strings are identical))
"no sound in ass"
Ok well i sprta figured it out. I forgot using namespace std; and string requires that. Then i learned that cin>> doesn't work with a string for some reason (error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion))
So i used the C counterpart: scanf("%s", filepath); (i think thats what it is). When i run the program then and enter a input i get an acess violation and it closes, heres the current code:
//Prorammed by Oleksi Derkatch/ Cinjection
//May 19 2005
//counts number of lines in programming projects.
#include <iostream.h>
#include <string>
#include <stdio.h>
using namespace std;
int main(){
int lines = 0;
string filetype;
string filepath;
bool error;
cout<<"Welcome to SPS Line Counter!"<<endl;
cout<<"Please enter the programming language."<<endl;
cout<<"Visual Basic = vb"<<endl;
cout<<"C/C++ = cpp"<<endl;
scanf("%s", filepath);
//exeption handling
do{
if((filetype != "vb")||(filetype != "cpp")){
error = true;
cout<<"...invalid file type!"<<endl;
cout<<"Visual Basic = vb"<<endl;
cout<<"C/C++ = cpp"<<endl;
scanf("%s", filepath);
}
else
error = false;
}while (error = true);
//end exeption handling
cin.get();
return 0;
}