Freaky_Chris 299 Master Poster

You probably forgot what you did in your original code.

string path = "\"C:\\Documents and Settings\\My Documents\\";

You need to encompass the address in quote marks, which means escaping them. Note the final quote will be after the extension so your code would be like this

string path = "\"C:\\Documents and Settings\\Music\\My Documents\\";
path += (rand()%5+1)+'0';
path += ".jpg\"";
system(path.c_str());

The segmant of code you asked about generates a number between 1 and 5, which i'm sure you are aware about. But since we wish to add the character value of that number to the string not the numerical value, we need to increaes its ascii code by 48 or '0' so that we get its character value. If that makes sense, try removing the +'0' and see what happens :P You'll get a bit of a surprise.

Chris

Freaky_Chris 299 Master Poster

please use [code=language] [/code] tags.

This is possible, create a string with the path and extension such as this

string path = "C:\\";
path += (rand()%5+1)+'0';
path += ".jpg";

Build your entire system expression like that, and then pass it like this system(path.c_str()) Chris

Freaky_Chris 299 Master Poster

So

if(result > 99999) return 0;

*mumbles about multiple exit points*

Chris

Comatose commented: :) +9
Freaky_Chris 299 Master Poster

It should be noted that using ifstream with >> operator defaults to skipping whitespace characters, which '\n' is also included in. if you want to proccess the'\n' in a special manner then you should use the following loop condition while(fp1 >> noskipws >> ch) Not that you do not need to check eof, the >>operator returns false if it cannot read anymore chars...end of file. Also eof() can be trigger by certain control characters and hence should never be used to check for the end of the file

Also if you are after one line, I would recommend using getline(). Not only is it simpler, but it also faster. Reading multiple bytes from a file at once is faster than reading byte by byte

Chris

majesticmanish commented: He saved my life +1
Freaky_Chris 299 Master Poster
class a{};
class b: public a{};
class c: public a{};

The very short example lol

Freaky_Chris 299 Master Poster

^^ My above posted answered that and explained why.

If thats all mark the thread as solved

Chris

Freaky_Chris 299 Master Poster

It's because open() expects a null terminated string rather than a string class. you can do the following

read_file.open(in_file.c_str());

Chris

Freaky_Chris 299 Master Poster

Using Win32 Development it will be platform specific. IE it will only work on M$ Windows.
http://www.winprog.org/tutorial/
That is a rather nice tutorial on how to get started. You should also use MSDN for a reference manual if you are seriously looking at writing unmanaged Win32 Applications!

Chris

Freaky_Chris 299 Master Poster

I think you're confusing people with the use of the word bit

Freaky_Chris 299 Master Poster
Freaky_Chris 299 Master Poster

I advise you use getline() for ALL data types and use string streams to convert them to int etc rather than cin.ignore()!


Chris

Freaky_Chris 299 Master Poster

do you fdefine your ClassName as a string or a char array?

Freaky_Chris 299 Master Poster

Use std::string with getline

#include <string>
...
std::string myString;
getline(std::cin, myString);

Hope that helps

Chris

Freaky_Chris 299 Master Poster

My exact thoughts but hey if it gets him to do his own work in future lol

Freaky_Chris 299 Master Poster

So where are your failed attempts, that was the point being made....we didnt say write it correctly then show it us...we said have a go and show us what you have and what it is you are having problems with

Freaky_Chris 299 Master Poster

What exactly do you mean by subset? as in are you trying to list all the different permutations of the numbers?

Freaky_Chris 299 Master Poster

Glad you got it fixed, just remember the number is the amount of array slots you get starting from 0...not what you get upto and including

ps mark as solved
thanks,
Chris

Freaky_Chris 299 Master Poster

we prefer to use strings with getline but there we go, it's a much more reliable solution since you don't have to worry about size

string test;
getline(cin, test);
cout << test.length();

Chris

Freaky_Chris 299 Master Poster

Sorry I missed the question. '\' is used to escape characters such as '\n' is a newline as you may well no or '\a' is a bleep. Because it's a special escape character in string you must escape it if you wish to use one. Hence the double slash.

Chris

Freaky_Chris 299 Master Poster

We'll give it a miss if you mark the thread as solved :P

Chris

Freaky_Chris 299 Master Poster

can you not see the () on open? Its just you have two parameters inbetween them :P

You will need to escape that '\' characters
"C:\\programs\\fileneedschanges"
Then t shold work fine

Chris

Comatose commented: :) +8
Bladtman242 commented: well, it solved my problem +1
Freaky_Chris 299 Master Poster

Here's a small example using vectors, it's nothing special, just something i made to show you how size does not matter.

#include <iostream>
#include <vector>
#include <string>
#include <ctime>

int main(void){
    std::vector<std::string> v;
    std::string text = "abcdefghijklmnopqrstuvwxyz";
    std::string temp = "";
    
    srand((unsigned)time(NULL));
    int x = rand() % 100;
    int z = 0;
    
    for(int i = 0; i < x; i++){
            z = rand() % 20 + 1;
            for(int q = 0; q < z; q++){
                    temp.push_back(text[rand()%26]);
            }
            v.push_back(temp);
            temp.clear();
    }
    
    for(int i = 0; i < v.size(); i++)
            std::cout << "v[" << i << "]: " << v[i] << std::endl;
   
    return 0;
}

Chris

Freaky_Chris 299 Master Poster

Firstly you should use

while(getline(myfile, line)){}

rather than

while(!myfile.eof()){}

this is because eof() can return true before the end of a file with some excape characters.

Secondly look into the vector header its wonderful its designed with this sort of thing in mind!

Chris

Freaky_Chris 299 Master Poster

you need to pass your vector by reference

Chris

Freaky_Chris 299 Master Poster

Your Welcome,
Go ahead and mark this as solved.

Chris

Freaky_Chris 299 Master Poster

Indeed createprocess is the much better choice, it gives you much more control over the outcome of everything.

BTW: IF it's solved could you please mark the thread as solved

Thanks,
Chris

Freaky_Chris 299 Master Poster

The concept is exactly the same, server/client or client/client it really is upto you. Lets say you go for server/client the more likely. Y9ou have the server set up to listen for connections and spawn new threads to deal with no connections recieved and forward data from an incoming socket to another outbound socket. The client will send a socket connection request to the servers IP address once connect is then free to recieve and send information as desired.

Chris

Freaky_Chris 299 Master Poster
ofstream myfile("example.txt", std::ios::app);

Hope that helps :P
app stands for append btw

Chris

Freaky_Chris 299 Master Poster

I agree with clockowl.
Anyway, when you say you were asked....by who your lecturer. Something tells me you wouldn't be asked to do something like this if you hadn't already been taught most if not all the material you need to do this. I suggest you look at winsock. It might be a good place for you to start...presuming your developing on windows and for windows OS's of course we don't know these things.

Chris

Freaky_Chris 299 Master Poster

Can i suggest you store the value of BM outside of the structure and store it in a char array of size 2 then write each one to the file before calling write() on the structure.

Chris

Freaky_Chris 299 Master Poster

erm did i miss something or do you not just want an array?

atom myAtoms[100];

Chris

Freaky_Chris 299 Master Poster

I will take your advice, and improve it. But cut me some slack :icon_lol: ...
I made this when I was 14 I think, didn't seem too bad at the time. XD

As for the control key always being left on, I could never quite figure out why that was happening, the keyboard hook stopped windows from processing it. I will try Block Input though, hopefully this is still helping chrischavez solve his problem (as well as mine) :D .

You need to pass the ctrl key press with the KEYEVENTF_KEYUP flag. That way it wont *stick* so to speak.

I guess blocking input might be a bad idea since then you have no way of using the ctrl lol....there might be a way to sort it out. have a play with it i guess.

Chris

Freaky_Chris 299 Master Poster

Not too bad William, the only one thing that annoys me about that is the fact that when pressing the ctrl key to simulate a left mouse click it is a big grrr. For example, you should either A) Block input on the ctrl key being sent and just send mouse input or B) Send a left ctrl key up event so that it is not stuck on!

Chris

Freaky_Chris 299 Master Poster

Sure.

POINT mousePos;
GetCursorPos(&mousePos);
std::cout<< "X: " << mousePos.x << std::endl;
std::cout<< "Y: " << mousePos.y << std::endl;

hope that makes sense.

Chris

Freaky_Chris 299 Master Poster

You can use SetCursorPos() to control the position of the cursor. It returns true is it succeeds and false if not. It takes 2 arguments int x and int y. You can use GetCursorPos() to retrieve the position of cursor. it returns the same as Set...() it takes one paramater a pointer to a structure of type POINT, which contains to values long x and long y. Also if you want to send Mouse clicks then you will need to look into the function SendInput() its well documented on msdn but feel free to ask for more information.

Chris

Freaky_Chris 299 Master Poster

that did absolutely nothing, but thanks for trying. I think the problem is that its not getting to the code for some reason maybe the while loop or something? i dunno but chris you prolly hit the code that said error cant open executable code.

Follow MosaicFuneral's Advice. the reason your program is terminating is due to the fact you have a vector of type string and you are trying to push an integer into it, see the problem?

Chris

Freaky_Chris 299 Master Poster

It worked fine for me. Try adding this at the end instead.

cin.ignore(100, '\n');
cin.get();

Chris

Freaky_Chris 299 Master Poster

When you create a pointer to a type you reserve enough space in memory for the the variable. When you call new you actually allocate the memory to the program so it cannot be used by another program.

Chris

Freaky_Chris 299 Master Poster

Your last else has no if to go with it.....

Chris

Freaky_Chris 299 Master Poster

Static memory space is generally very limited, if you want to create large array sizes then you need to use dynamic memory.

__int64 *array = new __int64[2000000];

But be sure to delete the array afterwards

delete []array;
array = NULL; // to make sure you do not use the pointer

Chris

Freaky_Chris 299 Master Poster

You're still calling srand() more than once.

Also try indenting your code and you might see your problem! Or at least stand a chance, thats too painful to try and read tbh.

Chris

Freaky_Chris 299 Master Poster

Have you made sure that your Window is actually in full screen, with borders etc removed? My guess is you are making your drawing space 3D but not the actual window.

You window should have properties that resemble the following.

hWnd = CreateWindowEx(NULL, L"WindowClass", L"Basic Window",
                          WS_EX_TOPMOST | WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
                          NULL, NULL, hInstance, NULL);

WS_EX_TOPMOST, making sure it is on top. Above start bar etc. WS_POPUP removes the borders etc, SCREEN WIDTH & SCREEN_HEIGHT are self explanatory. basically the resolution.

Chris

Freaky_Chris 299 Master Poster

What exactly do you mean, 'the image'. It could be a whole host of reasons.

Chris

Freaky_Chris 299 Master Poster

I think his answers your question...although i'm not entirerly sure :D

#include <iostream>
#include <vector>

using namespace std;

template <class T>
class test{
    public:
        test(T[]);
        void print();
    private:
        vector<T> v;
};

int main(void){
    char myArray[] = {'a', 'b', 'f'};

    test<char> myClass(myArray);
    myClass.print();

    cin.get();
    return 0;
}

template <class T>
test<T>::test(T example[]){
    for(int i = 0; i < (sizeof(example)/sizeof(*example))-1; i++){
        v.push_back(example[i]);
    }
}

template <class T>
void test<T>::print(){
    for(int i = 0; i < v.size(); i++){
        cout << "example " << i << ": " << v[i] << endl;
    }
}

Since you never posted what the problematic code was nor the error's you were getting.

Chris

Freaky_Chris 299 Master Poster

in your if statements you are assign the value of 0 and 1 to your variable a, thus it will always evaluate true. I'm guessing you should be using ==. Also since you have an unanitialized variable a, using the == would just be dangerous....

Chris

Freaky_Chris 299 Master Poster

oh the day of the week, my bad. Either way i'm sure you could have adapted the information given by that webpage it's not too complex.

#include <iostream>
#include <ctime>
#include <string>

using namespace std;

int main (void){
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  string day(asctime (timeinfo));
  cout << "Date: " << day.substr(0, day.find_first_of(" "));
  
  cin.get();
  return 0;
}

Chris

Freaky_Chris 299 Master Poster

Your question is a bit bizzare. What do you mean by week name?

But perhaps this would be helpful
http://www.cplusplus.com/reference/clibrary/ctime/localtime.html

Chris

Freaky_Chris 299 Master Poster

Visual C++ Express also has some nice stuff to it...so it's worth looking at both that and Code::Blocks and seeing which you prefer to work with....also VC++ allows you to used managed C++.

P.S If the you have your solution please mark the thread as solved.

Chris

Freaky_Chris 299 Master Poster

thats because of this line
int answer = atoi(av[1]);

av[1] will not exist, unless ac >= 2

Chris

Freaky_Chris 299 Master Poster
if (argc=='0'){

Do you realise what you are doing here?
argc is a number representing the number of command line arguments passed to your program. '0' is equivelant to 48, so you say if 48 command line arguments are passed then do X. I expect that is now what you ment to do.

theoretically the following should work

if(argc==0){
  //display error message or whatever cause no arguments passed!
}

However we then get into a whidely debated topic about the minimal acceptable number of commandline arguments.

Many operationg system pass the file name (or executable path) tothe application by default making the default length equal to 1 and then additional command line arguments added by the users will increase from there.

However it is not written in C++ ANSI Standards that the first commandline argument passed is equal to the filename/exectuable path. Thu making this much more difficult than you imagine.

However it is a reasonably safe assumption to assume that the first argument is the filename/executable path. Thus you can use the following.

if(argc==1){
// no custom arguments add do something
}else{
// argv[1] is equal to the first argument the user passed!
}

Hope all this helps.
(i'm probably gonna get grilled by some experts now :D)

Chris