Okay, so inline functions don't actually have to take up only one line. And placing a function inside a class? What's the rule that determins if it's an inline function or not?
Okay, so inline functions don't actually have to take up only one line. And placing a function inside a class? What's the rule that determins if it's an inline function or not?
I'm a little confused about inlining member functions. Does all code actually have to be on one line or does it simply mean writing the whole function inside the class rather than from outside using the :: syntax?
In the following program, where is pt1 getting it's values (1, 0)? I get pt3's values (5, 10) because I can see them in the code.
#include <iostream>
using namespace std;
class Point
{
private:
int x, y;
public:
Point() {}
Point(int new_x, int new_y) { set(new_x, new_y); }
void set(int new_x, int new_y);
int get_x();
int get_y();
};
int main()
{
Point pt1, pt2;
Point pt3(5, 10);
cout << "The value of pt1 is ";
cout << pt1.get_x() << ", ";
cout << pt1.get_y() << endl;
cout << "The value of pt3 is ";
cout << pt3.get_x() << ", ";
cout << pt3.get_y() << endl;
return 0;
}
void Point::set(int new_x, int new_y)
{
if(new_x < 0)
new_x *= -1;
if(new_y < 0)
new_y *= -1;
x = new_x;
y = new_y;
}
int Point::get_x()
{
return x;
}
int Point::get_y()
{
return y;
}
In the program below I'm a little confused with these two lines -> fbin.seekp(n * recsize);
& fbin.write(reinterpret_cast<char*>(&age), sizeof(int));
In the first one, why would we start writing to the file at position n * recsize instead of position 0? I would think that we would start writing at 0 and the jump to n * recsize for writing to the next block each time a write is made. And on the second line I'm confused about most of it. I've done simple type casting but what the heck is this? What is reinterpret_cast? Is it function, it doesn't have the syntax of one or is it just a built in keyword? Why are we casting as a char pointer or are we casting as a char pointer and what's the (&age)
all about? Thanks.
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdlib.h>
using namespace std;
int get_int(int default_value);
char name[20];
int main()
{
char filename[81];
int n;
int age;
int recsize = sizeof(name) + sizeof(int);
cout << "Enter file name: ";
cin.getline(filename, 80);
// open file for binary read and write
fstream fbin(filename, ios::binary | ios::in | ios::out);
if(!fbin)
{
cout << "Could not open file " << filename;
return -1;
}
//Get record number to write to
cout << "Enter file record number: ";
n = get_int(0);
// get data from end user
cout << "Enter name: ";
cin.getline(name, 19);
cout << "Enter age: ";
age = get_int(0);
// write data to the file
fbin.seekp(n * recsize); …
I have an iBasso digital music player and I need a little help uisng rsync. I want to copy all of my muisc from /home/garrett/Music/ into my SD card which is at /media/garrett/6BF6-AC8A/ I'm currently using the command rsync -a --delete /home/garrett/Music/ /media/garrett/6BF6-AC8A/
The thing is I would also like to transfer my audio books which I don't keep in my music directory, they are in /home/garrett/Audiobooks/ I would like to add the audiobooks direcotry to the command above but instead of only coping the contents of the Audiobooks directory the way it's doing with my Music directory I would like it to copy the directory itself and it's contents, not just the contents. Secondly how do I keep the command listed above from deleting the Audiobook DIR everytime it runs, I need it to make an exception for the Audiobooks DIR. Thanks.
Thanks mike_2000_17 I was thinking of starting with simple 2d graphics and animation for now rather than GUI or 3D programming. JasonHippy thanks, I'll give SFML a look.
This stuff seems pretty hard to break into.
I've been reading 'Learn C++ By making Games' and it uses the SDL library. The problem is the book has poor code examples, a lot of them don't even show the #include <libraries> instead jump straight to the main() function. So I just ordered the book 'Linux Graphics Programming with SVGAlib' believing it might be fun to work with only to discover that it's code is C, not C++ which is what I'm trying to learn. What's a good graphics library I could use with C++ on my Linux system, note that Windows compatibility is not important.
I know I probably need to be working on my php skills if I ever intend to have a job in IT but I just don't enjoy it, so I usually tinker with learning C++ towards simple game making on my Linux system.
Since the current value of $PYTHONPATH seems to be null I devided that overwritting it wasn't such a bad thing, my .bashrc file currently has this line -> export PYTHONPATH="$HOME/bin.libpy
" I have a very small program I'v written along with my imported library file but I'm still having problems.
Python program 'tags' in /home/garrett/bin/
#!/usr/bin/env python3
import sys
import MetaMP3.py
file = sys.argv[1]
tags = get_tags_mp3(file)
for i in tags:
print(i)
Current librar file MetaMP3.py in /home/garrett/bin/libpy/
#!/usr/bin/env python3
import sys
def get_tags_mp3(song):
f = open(song, 'rb')
position = -95
tag = b''
counter = 0
tags = []
for i in range(0,2):
f.seek(position, 2)
line = f.read(30)
position = -65
while line[counter] is not 0:
tag = tag + line[counter:counter + 1]
counter = counter + 1
counter = 0
tag = tag.decode('utf-8')
tags.append(tag)
tag = b''
return tags
Errors
garrett@mint-desktop ~/Downloads $ tags The\ Rains\ of\ Castamere.mp3
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2195, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/garrett/bin/tags", line 4, in <module>
import MetaMP3.py
ImportError: No module named 'MetaMP3.py'; 'MetaMP3' is not a package
I'm trying to add /home/garrett/bin/libpy/ to my python path so I can import my own libraries, I would also prefer not to overwrite the default python path but rather append my own path to the default. When I try to echo $PYTHONPATH
or $PYTHONHOME
I get nothing and even if I were to set it on the command line it wouldn't remain after the next reboot. I don't know where the config file for this is. Here's what the man pages had to say.
PYTHONHOME
Change the location of the standard Python libraries. By default, the libraries are searched in ${prefix}/lib/python<version> and ${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix} are installa‐
tion-dependent directories, both defaulting to /usr/local. When $PYTHONHOME is set to a single directory, its value replaces both ${prefix} and ${exec_prefix}. To specify different values for these, set $PYTHONHOME
to ${prefix}:${exec_prefix}.
PYTHONPATH
Augments the default search path for module files. The format is the same as the shell's $PATH: one or more directory pathnames separated by colons. Non-existent directories are silently ignored. The default search
path is installation dependent, but generally begins with ${prefix}/lib/python<version> (see PYTHONHOME above). The default search path is always appended to $PYTHONPATH. If a script argument is given, the directory
containing the script is inserted in the path in front of $PYTHONPATH. The search path can be manipulated from within a Python program as the variable sys.path.
In the following program what is ifstream
? It looks like it might be a Class name making file_in
an object of that class passing filename
as an argument but this particular book hasn't touched OOP yet so I wasn't sure.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int c; // input character
int i; // loop counter
char filename[81];
char input_line[81];
cout << "Enter a file name and press ENTER: ";
cin.getline(filename, 80);
ifstream file_in(filename);
if(!file_in)
{
cout << "File " << filename;
cout << " could not be opened.";
return -1;
}
while(1)
{
for(i = 1; i <= 24 && ! file_in.eof(); i++)
{
file_in.getline(input_line, 80);
cout << input_line << endl;
}
if(file_in.eof())
break;
cout << "More? (Press 'Q' and ENTER to quit.)";
cin.getline(input_line, 80);
c = input_line[0];
if(c == 'Q' || c == 'q')
break;
}
return 0;
}
Thanks mike, that answered my question.
One of my C++ books was showing the line cin.getline(arg, arg)
and later showing getline(cin, arg)
. Why is the second one not object.function and yet have the object as one of the arguments? What's the difference?
#include <iostream>
class Book
{
public:
Book(char* char*);
private:
char* title; // dynamic pointer to char array
char* author; // dynamic pointer to char array
public:
Book& Book::operator=(const Book& b)
{
if(this != &p) // make sure it's not the same object
{
delete [] author; // delete author memory
delete [] title; // delete title memory
author = new char[strlen(b.author) + 1]; // create new author
title = new char[strlen(b.title) + 1]; // crreate new title
strcpy(author, b.author); // copy author data
strcyp(title, b.title); // copy title data
}
return *this; // return reference for multiple assignments
}
};
int main()
{
Book* pA = new Book("Aardvark", "Be an Aardvark on pennies a day");
Book* pB = new Book("Speelburgh", "ET vs. Howard the Duck");
pA = pB;
return 0;
}
In the code above let's start with the declorations in the main function. What is Book* pA = new Book
Is that creating a pointer named pA that points to an object that has no variable name, only a place in memory and only accessible through the pointer variable pA? That's the only sence I can make out of this line. I've never used the keyword new
before and once again my book had decided that I don't need an explanation. What about his line -> Book& Book::operator=(const Book& b)
When I read a chapter on operator overloading I had a line that looked similar -> Rectangle operator+ (const Rectangle& p1)
but there we didn't use the …
I hope I can keep all of this straight. Thanks.
The book I'm using continues to give me code and fails to explain the syntax. I got to a chapter on operator overloading and it gave me some code but didn't actually explain any of the code. I having trouble understanding the Rectangle operator+ line and that methods contents. Why does there need to be a constant? why is there an & symbol at the end of Rectangle in the argument list? What is the difference between width and p1.width? Thanks
#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle()
{
width = 0;
height = 0;
}
Rectangle(int nx, int ny)
{
width = nx;
height = ny;
}
~Rectangle() {}
Rectangle operator+ (const Rectangle& p1)
{
return Rectangle(width + p1.width, height + p1.height);
}
int getWidth() { return width; }
int getHeight() { return height; }
private:
int width; // width of our rectangle
int height; // height of your rectangle
};
int main()
{
Rectangle ptA(1, 2); // create a 1x2 rec
Rectangle ptB(3, 4); // create a 3,4 rec
Rectangle ptC = ptA + ptB; // add them together
cout << "THe sum of RectangleA and RectangleB is:= (" << ptC.getWidth() << "," << ptC.getHeight() << ")" << endl;
return 0;
}
DonnSchwartz - I get what public, private, & protected are doing inside a class but I don't understand why it need to me in the class decloration of a derived class as shown in my line above.
Thanks guys, here's another question. While my book was explaining the difference between public and private within a class it have me this line class Hombre : public Man
but failed to explain why we would need to use public when creating a derived class.
What is the difference between these two classes? In the second one protected:
looking like it isn't doing anything at all, there's nothing under it umbrella.
class Tank
{
protected:
int wheels;
public:
void setWheels(int newWheels) { wheels = newWheels; }
int getWheels() { return wheels; }
};
///////////////////////////////////////////////////////////////
class Tank
{
private:
int wheels
protected:
public:
void setWheels(int newWheels) { wheels = newWheels; }
int getWheels() { return wheels; }
};
I recently re-installed my Mint system and now vim does not auto indent when writing code and has poor color coding. Does any one know what I need to change and where the config file for that is? Thanks.
I'm reading 'C++ Programming in easy steps' and the program the book has given me will not compile.
Compile line -> g++ -g -Wall "${ARG}" -o "${ARG:: -4}" &&
ARG is command line argument 1.
object.cpp:7:5: error: ‘string’ does not name a type
string color;
^
object.cpp:14:19: error: ‘string’ has not been declared
void setColor(string clr) { color = clr; }
^
object.cpp:18:5: error: ‘string’ does not name a type
string getColor() { return color; }
^
object.cpp: In member function ‘void Dog::setColor(int)’:
object.cpp:14:33: error: ‘color’ was not declared in this scope
void setColor(string clr) { color = clr; }
^
object.cpp: In function ‘int main()’:
object.cpp:26:26: error: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive]
fido.setColor("brown");
^
object.cpp:14:10: error: initializing argument 1 of ‘void Dog::setColor(int)’ [-fpermissive]
void setColor(string clr) { color = clr; }
^
object.cpp:28:39: error: ‘class Dog’ has no member named ‘getColor’
std::cout << "Fido is a " << fido.getColor() << " dog" << std::endl;
#include <iostream>
#include <string.h>
class Dog
{
int age, weight;
string color;
public:
void bark() { std::cout << "WOOF!" << std::endl; }
void setAge(int yrs) { age = yrs; }
void setWeight(int lbs) { weight = lbs; }
void setColor(string clr) { color = clr; }
int getAge() { return age; }
int getWeight() { return weight; }
string getColor() { return color; }
};
int main()
{
Dog fido;
fido.setAge(3);
fido.setWeight(15);
fido.setColor("brown");
std::cout << "Fido is a " << fido.getColor() << " dog" << std::endl;
std::cout << "Fido is " …
When you say 'member' are you refering to the, what would be an object if the structure were a class or something else?
I'm reading my C++ book and I've come to a chapter on structures and unions. The book has tried to explain the difference but I'm not getting it's explanation. Playing with the structure examples in the book reminds me of accessing attributes to a python Class but apart from that, probobly inacurate observation, I don't really get them.
In the program below what is the difference between rand and srand? My book says that rand returns an int between 0 and RAND_MAX, which is never smaller than 32,767. Yet this code returns a number from 1-6, how is that? I see the line ( rand() % 6 ) + 1
but I don't see how that would give a number from 1-6.
Thanks guys. I'll take a look at changing the root in the config file. Is there any reason not to use a web folder in my home directory instead of /var/www/ ? So for I've changed the owner to myself and the group to www-data, moved everthing to /var/www/html/ and it's working, just don't like changing from www to html.
I had to move all of my php and html files into /var/www/html/ instead of just /var/www/ and now it seems to be working just fine. I've never seen apache use /var/www/html/ by default before, why is it doing it now?
I just changed the group for www and all sub files to www-data but I'm still getting the same result. Any other ideas? I just found something by looking at the log file. It's looking in /var/www/html/file.php instead of just /var/www/file.php. I've never seen that before. Where is the apache config file I need to make that change in?
I just re-installed my Mint system and now I can't get php to work. I've tested apache and it seems to be working just fine, entering localhost into the URL brings up that default page in /var/www/ but when I created a small php file called testphp.php with nothing but phpinfo() function between to opening and closing braces all I get from the browser is NOT FOUND The requested URL /testphp.php was not found on this server. Any ideas what might have changed? After re-installing all I did was enter sudo apt-get install apache2 and sudo apt-get install php5
I changed SDL_Set_VideoMode to SDL_SetVideoMode and it almost worked. All it did was give me screen terrible resolution and a few errors on the command line as the program ran.
Fixed that now here's what I'm getting.
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
SDL_Surface *screen;
if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
screen = SDL_Set_VideoMode(640, 480, 16, SDL_FULLSCREEN);
if(screen == NULL)
{
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}
printf("Success!\n");
return 0;
}
initializing-sdl.c: In function ‘main’:
initializing-sdl.c:17:12: warning: assignment makes pointer from integer without a cast [enabled by default]
screen = SDL_Set_VideoMode(640, 480, 16, SDL_FULLSCREEN);
^
/tmp/ccSsAPkP.o: In function `main':
initializing-sdl.c:(.text+0x58): undefined reference to `SDL_Set_VideoMode'
collect2: error: ld returned 1 exit status
I copied the following from a back but I'm getting the erros that you see at the bottom of the page.
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
int main()
SDL_Surface *screen;
if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
screen = SDL_Set_VideoMode(640, 480, 16, SDL_FULLSCREEN);
if(screen == NULL)
{
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}
printf("Success!\n");
return 0;
}
Compile line -> gcc initializing-sdl.c -o sdltest \
sdl-config --cflags --libs``
Errors
initializing-sdl.c: In function ‘main’:
initializing-sdl.c:11:9: error: expected declaration specifiers before ‘if’
if(SDL_Init(SDL_INIT_VIDEO) != 0)
^
initializing-sdl.c:17:9: error: expected declaration specifiers before ‘atexit’
atexit(SDL_Quit);
^
initializing-sdl.c:19:9: error: expected declaration specifiers before ‘screen’
screen = SDL_Set_VideoMode(640, 480, 16, SDL_FULLSCREEN);
^
initializing-sdl.c:21:9: error: expected declaration specifiers before ‘if’
if(screen == NULL)
^
initializing-sdl.c:27:9: error: expected declaration specifiers before ‘printf’
printf("Success!\n");
^
initializing-sdl.c:29:9: error: expected declaration specifiers before ‘return’
return 0;
^
initializing-sdl.c:30:1: error: expected declaration specifiers before ‘}’ token
}
^
initializing-sdl.c:9:22: error: declaration for parameter ‘screen’ but no such parameter
SDL_Surface *screen;
^
initializing-sdl.c:30:1: error: expected ‘{’ at end of input
}
^
initializing-sdl.c: In function ‘main’:
initializing-sdl.c:30:1: error: expected declaration or statement at end of input
Again, I got this from my book.
I'm reading a book on C and it's telling me how to use gcc and about the -c option/flag. It reads "-c Compiles to an object (.o) file instead of an executable. This is important for creating library files." What is an object file and how is this good for library files? I'm assuming this is for creating files that don't have a main function and are used only as a resource for other programs. Is my understanding correct? If so could someone give me a 2 very simple(hello world simple) code examples of a program that uses a custom object or library file. Thanks.
Windows 8 was installed first because that's what came with the computer. Then I added to SSD for Linux, one for the OS and one for my home DIR. Everything worked fine until I just tried installing windows server 08, now I have to hit delete everytime the system is booting up and manually switch to Linux. And even though I change the boot order to the Linux drive the next time I turn the computer on again it will be set to the windows drive again.
I recently installed Windows Server 2008 and how my BIOS keeps setting the Windows boot as the default boot rather than Linux even though I keep setting the Linux SSD as the primary. Any ideas on why it keeps getting reset to Windows in the BIOS? I have 3 OSs on 3 different drives, Linux on a SSD, Windows 8 on a HDD, and Windows Server 2008 on it's own drive.
Also, after installing Windows Server 2008 I get the following errors.
File \Windows\system32\winload.efi
Status 0xc0000428
Any ideas there?
I haven't lost the files from my source DIR, it's all still there and all is still good. My issues are only in the destination DIR.
I have an iBasso DX50 digital music player and I have all of my music for it stored on a 128 GB micro SD card. I sync my music directory to it using the following command. rsync -a --delete SRC DEST
but I've noticed some odd behavior. I thought the --delete option would only delete files and directories in the destination that were not in the source but it did something a little strange, no it didn't remove anything from my source directory. I had two directories for the same album but one of them must have been slightly different and it only had one song in it. Then after syncing one day rsync must have deleted the directory with all the songs in it and left only the one that had only one song. How does --delete work that it would have this behavior and what can I do to fix it? Thanks.
I just tried installing MS Server 2008 R2 and it seemed to install fine but when I try and start it this is what I get and the black and white screen with all the BS.
File \Windows\systm32\winload.efi
Status 0xc0000428
Any ideas?
I'm trying to mount my SD card to my computer because the auto mount feature isn't working for some reason.
The card shows up on the first line of the 'lsusb' command, I know that's it because that line goes away
when I take the card out and re-run the command, so I know my system can see the device. Also, it should
be /dev/sdd because /dev/sdd also goes away if I take the card out and only appears when I run 'ls /dev'
and the SD card is plugged in. But there's only one FAT32 devie that appears when I run 'sudo blkid' and
that shows up as /dev/sdb2, and when I mount it and then look into that mounted directory it isn't the
contents of my SD card. Any ideas?
garrett@bedroom ~ $ ls /dev
alarm char full loop0 mcelog ppp ram14 random sdb2 sg1 stdout tty16 tty25 tty34 tty43 tty52 tty61 ttyS11 ttyS20 ttyS3 urandom vcs5 vcsa6
ashmem console fuse loop1 mem psaux ram15 rfkill sdb3 sg2 tty tty17 tty26 tty35 tty44 tty53 tty62 ttyS12 ttyS21 ttyS30 v4l vcs6 vcsa7
autofs core hidraw0 loop2 net ptmx ram2 rtc sdb4 sg3 tty0 tty18 tty27 tty36 tty45 tty54 tty63 ttyS13 ttyS22 ttyS31 vboxdrv vcs7 vcsa8
binder cpu hidraw1 loop3 network_latency pts ram3 rtc0 sdb5 sg4 tty1 tty19 tty28 tty37 tty46 tty55 tty7 ttyS14 ttyS23 ttyS4 vboxnetctl vcs8 vga_arbiter
block cpu_dma_latency hidraw2 loop4 network_throughput ram0 ram4 sda sdb6 shm tty10 tty2 tty29 tty38 tty47 …
For the past week I have been unable to update my Linux Mint 15 Cinnamon desktop. The shield at the bottom right corner of the screen just shows a red X, when I click on the shield and enter my password this is what I get -> http://pastebin.com/BpC29xhf
I'm looking at some towers on newegg and I'm trying to pick one out. I'm open to a full tower but I'd like to know if I can get away with a smaller case, mainly because of the price. I'd like to build a media server so the first priority is to have enough space and sata ports for multiple hard drives. One question in particular that I have about this is if there is a small case I could wrap around a larger HD to allow it to slide into a 5.25 external bay?
I punched in a model I seen on a sticker on the back of the case, this site is what I found -> http://www.ascendtech.us/gateway-gt4024-gt4026e-motherboard_i_mb4gat4001071r3.aspx
It shows a micro-BTX, so I'm guessing it's a pretty unusable case since everything is ATX or micro-ATX
It's an older Gateway tower, IDE connectors on the motherboard.
I just gutted one of my old desktop as am thinking about building a server. How do I know what size form factor this case needs. I'm assuming it's ATX or micro-ATX but I don't know.
The files I'm working on are all binary files, .mp3, .flac, & .wav. Does that help at all?
I tried tag as both a string and as bytes. I used tag = 'artist='
as well as tag = b'artist='
. I get the same error either way.
builtins.UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd2 in position 14: invalid continuation byte
I'm getting the following error that pops up not in my script but in the codecs.py file. I've used code exactly like this in another program and it worked just fine. Any ideas? Script below.
#/usr/bin/env python3
import sys
song = sys.argv[1]
file = open(song)
tag = b'artist='
for i in range(0,2):
for line in file:
if tag in line.lower():
print(tag)
In the following program I'm getting the warning -> unused variable ‘fn’. I'm following along with a book so I don't know why it gave me that portion of code if it's unusable. Also, I don't understand this line at all.
-> void(*fn)(int& a, int* b) = add;
#include <iostream>
void add(int& a, int* b) { std::cout << "Total: " << (a + *b) << std::endl; };
int main()
{
int num = 100, sum = 500;
int& rNum = num;
int* ptr = #
void(*fn)(int& a, int* b) = add;
std::cout << "Reference: " << rNum << std::endl;
std::cout << "Pointer: " << *ptr << std::endl;
ptr = ∑
std::cout << "Pointer now: " << *ptr << std::endl;
add(rNum, ptr);
return 0;
}
vegaseat If it's a directory that is already in PYTHONPATH, couldn't it already have modules in it? If so, would there already be an __init__.py file
?
Gribouillis Will the line PYTHONPATH="$HOME/pymods:$PYTHONPATH" not restore back to it's original state after a computer shutdown or restart? Will I need to add that line to .bashrc or .profile?