Freaky_Chris 299 Master Poster

More likely to be me, rather than you lol.

@OP
Agreed, post the source....or nobody will look at it.

Freaky_Chris 299 Master Poster

Re-word: He like many others does not trust exectuables presented to them from foreign, unknown sources on a programming website.

Freaky_Chris 299 Master Poster

I'm guessing from the PM you sent me, before creating this thread you found my code snippets. Why don't you look at those as a starting point. Also why didn't you follow the poliate adive I gave you of posting your attempt?

Since it is rare i respond to PM's

Freaky_Chris 299 Master Poster

So replace ".World" with ".Earth"
??

Chris

Freaky_Chris 299 Master Poster

all of the lines to your if statement should be wrapped in {}.

Also using cin>> is a step backwards from getline() you should read the stick "How do I clear the imput buffer?"

Chris

Freaky_Chris 299 Master Poster

Also on a side note, alot of fps's hide the actual player model and then have seperate higher detailed models for the arm/gun specially for the first person view. This will obviously solve most clipping problems as well.

This will not be a solution to clipping issues, the near viewing plane reduction is the fix to the clipping issue. rendering different objects does nothing to what the camera can see

Freaky_Chris 299 Master Poster

Sounds like you actually want something like this....

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, char *argv[]){
    ifstream example("Exmaple.txt");
    string line;
    istringstream iss;
    vector<int> part1;
    vector<int> part2;
    int temp1, temp2;
    
    while(getline(example, line)){
                           line.replace(line.find(";"), 1, " ");
                           iss.clear();
                           iss.str(line);
                           iss >> temp1 >> temp2;
                           part1.push_back(temp1);
                           part2.push_back(temp2);
    }
    example.close();
    
    cout << "Part 1:" << endl;
    for(int i = 0; i < part1.size(); i++)
            cout << part1[i] << endl;

    cout << endl << "Part 2:" << endl;
    for(int i = 0; i < part2.size(); i++)
            cout << part2[i] << endl;
    
    return 0;
}
StuXYZ commented: tight clean code +4
Freaky_Chris 299 Master Poster
istringstream iss;
iss.str("56");
int x;
iss >> x;
if(myArray[y] == x)
  cout << "They match! at array position: " << y;
Freaky_Chris 299 Master Poster

Post a sample of your input file and a sample of what your output should be, and what output you are getting please.

Chris

Freaky_Chris 299 Master Poster

your desciption indicates that you will be given a list of random numbers that will be in no particualr order. thus you cannot just loop through the array backwards. You will need to perform some form of sorting algorithm such as a Bubble Sort

Chris

Freaky_Chris 299 Master Poster
#include <fstream>
#include <string>

int main(int argc, char *argv[]){
    std::string example = "Hello, world!\nHow are you?\n\tSuper thanks!";
    std::ofstream exfile("test.txt");
    
    if(!exfile.good()) return 0;
    exfile << example;
    
    exfile.close();
    return 0;
}

I see no whitespace problem...

Hello, world!
How are you?
	Super thanks!

Chris

Freaky_Chris 299 Master Poster

You could use stringstreams to convert the string into an integer. Or you could use atoi() or even better strtol() you can research all of these on the nternet, they are all well documented, if you are still stuck then get back to us. (String streams would be the best approach!)

this line is the problem: while (y < 5 && ids[y] != searchForId) "searchForId" is a std::string and ids[y] is an int. You can't compare apples to pears in c++ :)

Think he is already aware of this, but doesn't know what to about chaning that

I believe that it is because I am using the string searchForId and the array is an integer

Chris

Freaky_Chris 299 Master Poster

Do some research on google, then come back with yuor findings and we will spread some more light on it, but it sounds to me like a homework question and you are looking for a copy and paste answer!

Chris

Freaky_Chris 299 Master Poster

http://msdn.microsoft.com/en-us/library/aa364946(VS.85).aspx

:) or you could probably count the number of characters in the file in binary mode the multiple it by 8??

Freaky_Chris 299 Master Poster

lol Year sorry, I wasn't really thinking, just stuck the numbers in without thinking :P

Freaky_Chris 299 Master Poster

Fair enough, I wasn't taking into consideration the length of the number. Although yould I reccomend strtol() instead of atoi().

Chris

Freaky_Chris 299 Master Poster

I still think tat you should look at the modulus symbol

Freaky_Chris 299 Master Poster

please don't use TEX tags, just do number%10000000

Chris

Freaky_Chris 299 Master Poster

You should have all prototypes in the header file and the full function delarations in the external file.

Chris

Freaky_Chris 299 Master Poster

It's quite alright. Well I figured you would already have been using srand() :P

Chris

Freaky_Chris 299 Master Poster

Some of your header files are missing .h extensions

This is C++ not C
Infact he has extra header file that he shouldn't have such as time.h

Please try to get things reasonbly accurate before making a point of it

Chris

Freaky_Chris 299 Master Poster

Ask whereever you got the mod from, we know nothing about this.

Freaky_Chris 299 Master Poster
if (h < 0)
{
   return 1; // error code +1 = underflow hours
}
else if( h > 59 )
{
   return 2; // error code +2 = overflow hours
}

:)

Freaky_Chris 299 Master Poster

The best way would be to use string streams

#include <sstream>
...
ostringstream oss;
oss << "\"C:\\Documents and Settings\\";
oss << rand()%1000 + 1;
oss << ".jpg\"";

system(oss.str().c_str());

Chris

Freaky_Chris 299 Master Poster

I would do something like this,

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <fstream>

using namespace std;

struct cell{
    int value;
    string pos;
}cellData;

int main(void){
    ifstream ins("example.txt");
    if(!ins.good()) return 0;

    vector<cell> data;
    string line;
    istringstream iss;

    while(getline(ins, line)){
        for(int i = 0; i < line.length(); i++)
            if(line[i] == ';') line.erase(i, 1);
        iss.clear();
        iss.str(line);
        iss >> cellData.value >> cellData.pos;
        data.push_back(cellData);
    }
    for(int i = 0; i < data.size(); i++)
        cout << "Value: " << data[i].value << " (" << data[i].pos << ")" << endl;

    return 0;
}

I would not reccomend atoi() it's error response is poor, if you wish to do it this way I would say use strtol() (yes thats right to long, but at least it can return errors!). But I would just use string streams as you can see from above.

neik_e is correct, do not use eof() it can return true on some escpae characters so it's not advised!

Chris

Freaky_Chris 299 Master Poster

What agni is suggesting is you do something like this, and then do a search on the name for the inputted name and output the corrisponding number.

#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

struct data{
       string name;
       int number;
};

int main(void){
    vector<data> FileData;
    data tempData;
    ifstream ins("example.txt");
    string dataline;
    istringstream iss;
    
    while(getline(ins, dataline)){
                       iss.clear();
                       iss.str(dataline);
                       iss >> tempData.name >> tempData.number;
                       FileData.push_back(tempData);
    }
    
    for(int i = 0; i < FileData.size(); i++)
            cout << FileData[i].name << '\t' << FileData[i].number << endl;

    return 0;
}

Chris

Freaky_Chris 299 Master Poster

Yes you would :)

Freaky_Chris 299 Master Poster

You can check out the Win32 Reference at MSDN too.

You might find these links quite nice though.
http://www.winprog.org/tutorial/ <-- Very well known
http://www.relisoft.com/win32/index.htm <-- Highly vetted for

Chris

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

I'd think about how to check if a file is really open :)

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

Guess what, there's only one person at this forum who is capable of getting the answer and thats YOU!

Chris

Sky Diploma commented: Good Answer ;) +1
Freaky_Chris 299 Master Poster

You missed to read about the forum posting expectations and proper code tagging.
I suggest you stick around and learn why your posted code is not a good example.

READ!

Freaky_Chris 299 Master Poster

Um sounds to be link you want something like this.

aVariable += anotherVariable;
Freaky_Chris 299 Master Poster

I'd consider reading about stringstreams and better methods of processing inputted data.
http://www.daniweb.com/tutorials/tutorial71858.html

Chris

Freaky_Chris 299 Master Poster

Sounds to me like you need to do some work yourself. I'd start by Googling Permutations.

Chris

Freaky_Chris 299 Master Poster

You might want to shoot me before you start reading but meh lol.

I use Google Chrome.....*runs* on my older PC because it's somewhat faster than the alternatives.

Anyway basically drop down menu's don't work. Instead of being given the drop down menu it just redirects you to the default link.

Don't know whether you want to do anything about it after all. Google Chrome is every web developers nightmare!

But I just thought i'd let you know.

Cheers,
Chris

Freaky_Chris 299 Master Poster

Please use code tags!

Amen to Salem being a bot ;P

You posted it everywhere...pretty lame lol. What amazes me is how you managed to come up with code for permutations, but cannot write what appears to be a simple loop....

Chris

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

Rebuild the debug version and it should work fine. Might I add that your first method should be run the program from the Command Prompt, rather than using cin.get(); Since they are technically supposed to be run from the command prompt...it will also allow you to see your output.

Only use cin.get(); if you really must.

Chris

Freaky_Chris 299 Master Poster

Mod please close this thread.

Freaky_Chris 299 Master Poster

yes it is possible to arrange in one array .

Do you feel the need to echo me?

Freaky_Chris 299 Master Poster

You can do it in one array

char array[3] = {'a', 'C', 'b'};
char temp;
temp = array[2];
array[2] = array[1];
array[1] = temp;

Chris

Freaky_Chris 299 Master Poster

For basic ASCII which I presume you will be using, then you can just check the character range. and swap accordingly. IE, 65-90 is capital etc

Chris

Freaky_Chris 299 Master Poster

zalezog please don't add cin.get() to the end of people code snippets, they are not wrong by not using it. I would be more inclined to say you are wrong in using it.

Chris

StuXYZ commented: I really hate trailing get/pause etc. +3
Freaky_Chris 299 Master Poster

If I am correct compilers will automatically generate a default blank destructor for you anyway on compile time if non is specified. But I think it's good practise to make sure you include a destructor whilst learning about classes. If you don't you'll forget about them and when you come to mixing pointers and classes you'll completely forget and end up with memory leaks.

Chris

Freaky_Chris 299 Master Poster
#include <fstream>
...
std::ifstream myfile("blah.txt", std::ios::binary | std::ios::in);

Chris

Freaky_Chris 299 Master Poster