Windows API, http://msdn.microsoft.com/en-us/library/aa446854(VS.85).aspx, or?
MosaicFuneral 812 Nearly a Posting Virtuoso
MosaicFuneral 812 Nearly a Posting Virtuoso
They're for abruptly "breaking" loops.
No. No-one will write code for you, unless you're their respectable employer, teacher, or project partner.
First function is missing a semicolon.
Why do you declare and define another function inside of a function?
Why not use a container if you don't know how to use an array?
Why are you using the class keyword public?
You can also just check the right-most bit of a value, to see if it's an odd or even.
What???
Except I doubt his authority, due to lack of English skills. And receiving an IP from admin; why should you be given that, Ron?
You tried to screw with a third element, but you only have the array set to [2].
It's also i < 3
not <=
This goes in header:
class FileHandler
{
private:
vector<string> lines;
public:
void open(const char *name, const int &mode);
}
Your code goes in C++ file:
void FileHandler::open(const char *name, const int &mode)
{
//place it into vector
}
And as I said, try to leave questions in the forums, not PMs.
One, site rule, CodeTags!!
Two, use functions void FileHandler::open(const char *name, const int &mode);
.
Three, don't bother with eof(). Try, while(getline(file, line))
.
Two threads up, as a Read Me sticky.
ifstream inFile; vector<string> data; inFile.open("File.txt"); while (!inFile.eof()) { string sString = inFile.getline(); data.push_back(sString); }
Don't bother with eof(), and don't put declarations in loops.
Simplified:
ifstream file("name");
vector<string> lines;
string str;
if(file.is_open())
{
while(getline(file, str))
{
lines.push_back(str);
}
file.close();
}
else
{
failed. set error events, logs, etc.
}
They're for abruptly breaking out of loops, which beginners confuse with goto some reason(never use goto!).
uhmmm.... Get a compiler from this century. Strings are a million times easier than what you're doing now.
ofstream file("name", ios::app);
if(file.is_open())
{
cout << "Opened." << endl;
file << " appending data";
file.close();
}
else
{
cout << "\"Could not open file.\"" << endl;
}
cout << "Done.";
It's <iostream> not <iostream.h>, try <string> not the old C way.
By using string you can simplify it and create an easier to follow flow of code. http://www.cplusplus.com/reference/string/string/
And by the way, main() must return zero.
Just using the string vector as an example.
void B::push_back(string &str)
{
array.push_back(str);
}
string B::get_string(int element)
{
return(array[element]);
}
If you use a pointer it should be private(imo), allocated in the constructor, deallocated in the destructor, no direct-access. Just my paranoid way.
Don't use gotos, there is break;
and things called functions.
Why are you closing it if it doesn't open?
Re-write it.
That's some dangerous looking code.
class B
{
private:
vector<string> array;
public:
void method_add(int &stuff, int more);
};
void B::method_add(int &stuff, int more)
{
stuff += more;
}
class A
{
private:
B objectB;
public:
void do_something(void);
};
void A::do_something(void)
{
int a = 7, b = 9;
objectB.method_add(a, b);
cout << "A.do_something().a: " << a << endl;
}
I would suggest you look for some more class tutorials.
help here again... if i enter AaBbCc the output should be CcBbAa or cCbBaA.. but the output appears cbaCBA.. help!!! heres the code..
#include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> #include<search.h> //int joke(const void* x,const void* y); void main() { clrscr(); char a[100],temp; cout<<"Enter string: "; cin>>a; for(int i=(strlen(a)-1);i>=0;i--) cout<<a[i]; cout<<"\n\nLETTERS IN THE STRING: "; for(int b=0;b<(strlen(a)-1);b++) { for(int c=b+1;c<(strlen(a));c++) { if(a[b]<a[c]) { temp=a[b]; a[b]=a[c]; a[c]=temp; } } } cout<<a; getch(); }
You need to clean up your coding habits -just a bit- to help yourself out, while working with it:
C++ files don't have .h, so it's <iostream>. Important to remember, since <string.h> is very different from <string>.
Also try C++'s string with built in functions of convenience.
Place your sorting method in a function to clear things up a tad.
Use newlines to space out parts of your code.
main() must return zero.
clrscr(), is that portable?
Now as Vernon recommended, just need to compare it in one case then flip it back keeping track of it with a boolean statement.
Or just:
ifstream file("name");
sting str;
if(file.is_open())
{
file >> str;
file.close();
}
If you're parsing a string, then possibly substring it and use istringstream to place it into an int.
You'd probably also have to check the string size(counting till non-num found), and compare it to string.max_size().
Here goes your code. Its compiled.
Syed, did you read any-of the rules, before you even posted?
If it can't open it then why do you continue to use it afterward?
file open
if(is open)
{
do stuff
close
}
else
{
print "Error"
}
You're also missing a return.
Site rules "CODE TAGS".
Few things wrong, no need for system("pause");
C++ has it's own input tools, you never close() the file very BAD!, why do you need exit()?
ifstream infile;
infile.open("file");
if(infile.is_open())
{
do stuff here;
infile.close();
}
else
{
cout << "Error occured." << endl;
}
Have you tried different file attributes and access levels, like just all read, no hidden stuff, etc.
You're not modifying the variable, just taking it as a parameter.
Do you have to use recursion and not a loop?
"You have been trained well." lmfo, That was pure brilliance.
1 e:\psgitd~1\finals~1\greatest.cpp
iostream.h: No such file or directory
Because it's #include <iostream>
no ".h".
Remember to stream for larger things, like music, instead of loading it completely.
Then kick your professor in the shins for it. Place the declaration in a header, and link the definitions.
String path can't just be placed in a printf like that, it has to be c-string format: path.c_str()
Why not just use cout since everything is taken care of for you, if you're not willing to format it.
And you might want to read the forum rules - IMMEDIATELY! Pay attention to that part about "code tags".
Class awsome is not a pointer you don't use ->
.
Oopy.cpp missing something on the include?
Your class is missing a semicolon to finish it.
Well if you know basics, then you could try out SDKs like SDL, Allegro, whatever, or try looking for game engines that have things like renders, scene loaders, event handling and such already made so you can spend more time on your games actual development.
What's the question???
Do you even know how to program in C++? That would be the first step towards doing anything.
Have you you tried compiling it, and reading the error reports? There's invalid operations, spelling mistakes, missing types, definitions where there shouldn't be, et al.
I think you need to start anew, slowly adding piece-by-piece, compiling, fixing, learning, and so on.
You also might want an IDE to help do the indenting for you, as you go along.
What is line 10, and 11?
main() must be able to return zero, and there really is no file called <iostream.h>, look it up.
Is getche() a typo, or do you really need it?
Biggest question: is your tab, or space bar broken? You'll never be able to fix something no-one can read, I just stop after several lines, and scrolled through the mess.
Take the initial time with time()
, use inside a loop take the time again, then use difftime()
to check the diffrence between the two; if it's greater than the max time, break the loop.
Tell them to use it, and search for the char with '.'
.
I've spotted three right off the bat.
Have you tried abc = f_path;
?
And if I try to use the Print(); funtion, that makes the program close. Any help?
What Print()
function?
In the case the you only had to use ASCII values 32-126, you then could share a single byte for two values. You could even use a truth table that points out the positions of a nibble that is really its opposite extended version 128-255.
I pretty sure there's a better way of drawing the scene with an initial array that you print in a loop, then add the new characters to the array every new state.
You can put the BinaryNode struct outside of the class and make the class look a little more cleaner.
Why are you including the .cpp file, it's not a header?
Shouldn't the destructor test if the pointers are NULL first?
Get DOS and use Mode 13h, lol ;)
You have to get the max console size, then use SetConsoleDisplayMode()
edit: Actually I think you need WinXP for it, sorry.
Can I see the part where you try to access the NumDays()?
Just open the Windows directory and take your pick on what to use against it. Registries, .infs, replace .exes with .coms, find a minor glitch, etc.
See if this works:
int isNum(char c)
{
if((int)c > 47 && (int)c < 58) { return(true); }
return(false);
}
First you're using the wrong "OR". For comparisons it's "||", not the bit-operation 'or' "|".