| View previous topic :: View next topic |
| Author |
Message |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sat Jan 14, 2012 5:08 pm Post subject: [C/C++] File output is jibberish |
|
|
| Code: | #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
class Food{
public:
Food(string argName, int argX){
x = argX;
name = argName;
}
void logCarb(){
FILE * carbFile = fopen("CarbsList.txt", "a");
if(carbFile != NULL){
fprintf(carbFile, "%s Testing %d", this->name, this->x);
fclose(carbFile);
}
else
cout << "Something failed";
}
int x;
string name;
};
int main(){
Food *k = new Food("Potatoes", 30);
k->logCarb();
return 0;
} |
My output in the file comes out as crazy shit like this:
| Quote: | | ӕcӕ] Testing 1635020624 |
Does anyone see any inherent errors causing this?
Disregard the shitty code, thanks guise.
_________________
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Jan 14, 2012 6:50 pm Post subject: |
|
|
name is std::string, it is going to print the pointer since you told it to use the object. Use this->name.c_str() instead.
_________________
- Retired. |
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sat Jan 14, 2012 8:24 pm Post subject: |
|
|
Ah, I see. Thanks
Fixed.
Understood.
Moving on.. lol
_________________
|
|
| Back to top |
|
 |
|