Hello :)
Quick question:
while(1){
if(GetKeyState(VK_SHIFT)<0){ //if SHIFT pressed
cout<<"control "<<endl;
if(GetKeyState('a')<0){ //if SHIFT is still being pressed and...
Type: Posts; User: CPlus
Hello :)
Quick question:
while(1){
if(GetKeyState(VK_SHIFT)<0){ //if SHIFT pressed
cout<<"control "<<endl;
if(GetKeyState('a')<0){ //if SHIFT is still being pressed and...
Where does the 'foo' come from? I see the 'bar' declared for the string.
Thanks :)
Thanks guys. Okay this is what I have so far:
class IntStr
{
private:
typedef enum { INTEGER, STRING, UNION } MyType; //INTEGER, STRING, UNION are defined into MyType
...
I just looked up a tutorial and saw
"These [operator] functions return a reference to the stream object so that these operators can be chained together ( e.g. cout << "the answer is" << i << endl;...
Oh I was hoping to relate to the mTypeInfo within the class. Overloading operators must be done outside of the class and referred to with friend, right?
Is the operator>> incorrect because of the...
Thanks.
Would it look something like this?
ostream &operator<<(ostream &output, IntStr intstr)
{
if (mTypeInfo == INTEGER)
output << intstr.mInt;
Thanks, it works WhiteFlags.
How do I use the << operater on the IntStr type?
I tried this:
IntStr IntStr::operator<< (IntStr argument)
{
In order to overload <<
would I do something like this:
IntStr operator<<(const int index) //index number with associated element
{
return v.at(index);
}
Can it be done with a union?
I was using struct because I noticed the compiler did not complain by doing
vector<IntStr>
before the struct IntStr was completed.
Yeah but I'm still learning things though. I'm a C++ programmer since I use C++, but I never said I was good at it.
I just take notes as I go along :)
Is there a way to do this:
#include...
I went ahead and added the constructors:
struct IntStr
{
int i;
IntStr(int x): i(x) {}
string s;
IntStr(const char* y): s(y) {}
Oh okay. This is where I'm lost. I don't know much about structures aside from their class-like nature.
I don't know how to use constructors, but would a constructor look like this?
struct...
Is there any way to do this?
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct IntStr
Oh okay. I tried with 2 stars but it doesn't compile for some reason.
string** a[2]; //visually : { a[0] , a[1] }
a[0] = new string[2]; //visually : { {a[0][0],a[0][1]} , a[1] }
...
Is it possible to do something like this
string* str[2]; //allows str[0] & str[1]
str[0] = new string * [2]; //allows str[0][0] & str[0][1]
str[1] = new string * [3]; //allows...
Is it possible to have jagged arrays using normal arrays?
Something like
int i[2]; //makes i[0] and i[1]
i[0] = new int[2]; //makes i[0][0], i[0][1]
i[1] = new int[3]; //makes...
Hello :)
Is there a function (call it nest for this example) that nests vectors?
Like this
nest("char",3); //Result: vector< vector< vector<char> > >
nest("string",2); //Result: vector<...
Hello :)
Is there a way to perform mathematical operations with the following custom datatype:
#include <iostream>
#include <string>
#include <vector>
#include <boost/variant.hpp>
Oh no I didn't. Whoops. I will look into that right away.
Thank you LaserLight and Elysia for your points. It's true that C++ isn't making this easy :p .
Hello :)
This is to anyone who needs the following:
Dynamic array (the size is defined at run-time)
Mutable array (the characters within the array can be edited)
Spaces allowed (the input...
Yeah you both have good points there.
To be honest, I don't actually have any concrete projects in mind. I'm trying to learn many ways to go about doing things in case I need them in the future...
This is probably a sinful answer amongst you guys, but the simplest answer is...
Because I'm lazy :p
Looking at this portion:
c.push_back(IntStr(123, "abc"));
cout << c.at(0) << endl;
Is there any way to extract IntStr's individual parameters?
Hello :)
Is there any way to do this?
(Green is working code, Red is non-working code)
int main()
{