|
_Flaviu wrote:
#ifdef SID
typedef ... SID;
Sorry to be rude, but that's bullsh1t! If there really is a #define for the symbol SID anywhere in your code or your precompiler options, then your ccode will most likely never compile, because any attempt to use, declare or otherwise reference a struct SID will be turned into garbage by the precompiler which replaces the symbol with something else!
So, unless and until you make sure that nobody does such a #define , there is no point looking further! And then, of course, the #ifdef makes no sense - not that it did before.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
|
|
If I wrote:
#define major(dev) gnu_dev_major(dev)
#define minor(dev) gnu_dev_minor(dev)
then I got following error:
error C3861: 'gnu_dev_major': identifier not found
error C3861: 'gnu_dev_minor': identifier not found
I have arrived in a kind of same error ...
|
|
|
|
|
Didn't you read the link I have posted? There are some definition of the functions...
Just try something like
unsigned int gnu_dev_major (unsigned long long int __dev)
{
return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
}
|
|
|
|
|
Ahh, I didn't read whole source code. I am struggle to solve another errors. But I implemented what you said and I get rid of that error. Thank you Victor !!!
|
|
|
|
|
You are welcome!
But be sure that this function definition is correct!
|
|
|
|
|
It looks like you're trying to use a GCC/linux function under Windows. Does that even make any sense? I mean, I've seen that you got it to compile now, but that doesn't mean your program will do what you expect it to!
I'm not familiar with gcc/linux and these functions, but if what Victor posted corresponds to the original implementation, it looks like dev is some version identifier composed of a major and minor version number. The way such versions are composed in Windows may be entirely different! There's no common scheme for it between different applications, compilers, or the OS itself. So don't expect any correct results from a Linux implementation!
To properly solve this issue you should find out who uses these functions and what are they expected to return. Only then will you be able to implement a proper replacement. Or, better, find the corresponding functions provided in Windows.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
"find the corresponding functions provided in Windows" I am perfectly agree with you. This is another part of work. And I am not sure that I'll find such replacement.
modified 9-Jan-20 4:56am.
|
|
|
|
|
Yes, it's entirely possible you won't find a match. That is the problem with language extensions, and the reason why many projects insist on staying compatible to the C++ standard instead.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
This is a corollary on an old issue of cout and perror (cerr) output not following expected sequence.
I understand that is caused by cout and perror(cerr) outputting to DIFFERENT streams. End of story for now.
Now I am having issues with inserting setw and left into cout NOT doing what I expect.
See attached IDE output. (Align cout text left starting on column set in setw.)
setw(30) without left is also being totally ignored, until width is set to 75 (?).
What gives?
PS in Linux if it should make a difference.
To avoid any unnecessary replies - usual note that I am looking for a solution to an issue, not for commentaries on my code style.
Cheers
else if (child > 0) {
cout << setw(75) << left
<< "\033[1;31mINITIALIZE bold red text\n" << flush;
cout << flush; cout << setw(75) << left << "(offset 30 ) START PARENT PROCESS "
<< endl;
#ifdef DEBUG
cout << setw(75) << left
<< "parent has / knows child process ID " << dec
<< child << endl;
cout << setw(75) << left
<< "TRACE This is the parent, orignal process "
<< endl;
cout << setw(75) << left << "TASK @line " << dec << __LINE__
<< dec << endl;
cout << setw(75) << left << "function " << __FUNCTION__ << endl;
cout << setw(75) << left << "STOP @line " << __LINE__ << endl;
cout << setw(75) << left
<< "child > 0 File descriptor socket[0] " << dec
<< sockets[0] << endl;
cout << setw(75) << left
<< "child > 0 File descriptor socket[1] " << dec
<< sockets[1] << endl;
#endif
Actual output on IDE console
START test area 370
main
TASK create a pair of connected sockets
TRACE @line 403
SUCCESS opening stream socket pair
result 0
socketpair File descriptor socket[0] 11
socketpair File descriptor socket[1] 12
TRACE @line 420
TASK fork Create another process child default -1
TASK @line 427
function main
TRACE @line 429
INITIALIZE bold red text
(offset 30 ) START PARENT PROCESS
parent has / knows child process ID 11713
TRACE This is the parent, orignal process
TASK @line 451
function main
STOP @line 453
child > 0 File descriptor socket[0] 11
child > 0 File descriptor socket[1] 12
child process , not ID ! 0
TRACE This is the child. process
TASK @line 513
function main
|
|
|
|
|
You do know that left applies to the output stream until its changed with either right or internal , don't you?
Anyway, the only odd thing I can see is this bit
INITIALIZE bold red text
(offset 30 ) START PARENT PROCESS
Your code is:
cout << setw(75) << left
<< "\033[1;31mINITIALIZE bold red text\n" << flush;
cout << flush;
cout << setw(75) << left << "(offset 30 ) START PARENT PROCESS "
<< endl;
In that first line, you have a terminating \n , so the output stream sends your text, including the line terminator, then fills the output so that 75 chars are actually written, since the cout string is 32 chars long, you get an additional 43 spaces to make up the output width before the next cout . Remove the terminating \n and add a << endl .
Otherwise, it all looks good to me. Changing the width to 35 seems to do the right thing, and removing the left right-justifies the output, which I think is correct, so I'm not sure what you're seeing that's wrong. Maybe give us an example of what output you get when it seems incorrect to you, please.
|
|
|
|
|
PLEASE DISREGARD ALL OF THE FOLLOWING.
I AM USING SETW INCORRECTLY.
I need to check this more, but ...
with
cout << set(x) << left << "TEXT " << data << endl; ..
I expect TEXT to be output starting at column x and left justified.
As of now the data is output at unexpected column - as you pointed out.
Did I misinterpret setw - as it appears to set the width of the entire cout message , not just setting the starting column?
The "flush" ( clear cout buffer ) should have no effect on the actual output, it is there as an attempt to fix another issue.
However - endl at each cout line should also clear the cout buffer , hence each line should start independently - which it does.
The whole snippet is part of TWO processes output and I need to try this setw in single process FIRST! It appears that cout does not run in each process independently, so let me eliminate the child process.
I am also not sure if "\n" clears the cout buffer.
modified 6-Jan-20 0:49am.
|
|
|
|
|
The setw() manipulator (<iomanip> functions | Microsoft Docs[^]) just sets the minimum width of the next field to be output. So whatever is in that field will be output (after converting to text if necessary) in a field that is at least that many characters wide. If the text is wider than the setw value then it will overflow the field.
As to your other comments above, setw has nothing to do with which column the output will start at.
Vaclav_ wrote: It appears that cout does not run in each process independently It sort of does, but ultimately they both feed into the same stream that is managed by the console handler.
Vaclav_ wrote: I am also not sure if "\n" clears the cout buffer. No, it is just a character sent to the stream, but I think the console handler converts it to CR LF . The end of output is sensed by the presence of the endl manipulator.
|
|
|
|
|
Vaclav_ wrote: Did I misinterpret setw - as it appears to set the width of the entire cout message , not just setting the starting column?
Looks like you figured out where you went wrong with setw() , but I'd like to point out that setw sets the width of the next output field, but does not truncate, so cout << setw(5) << "Hello World"; will still print all of the string "Hello World".
If you really want to put output at a specific location on screen, maybe take a look at curses: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
|
|
|
|
|
Quote: usual note that I am looking for a solution to an issue, not for commentaries on my code style

|
|
|
|
|
Trying to convert a linux project to windows, I met an error (from the subject of the post). I have a chance to use something else in windows case ?
if(S_ISDIR(type))
....
where type is defined as mode_t type ... and mode_t is another error:
error C2061: syntax error : identifier 'mode_t'
how can I solve these errors ? I seek on internet and I found something like:
#if defined __WIN32__ || defined _WIN32 || defined _Windows
#if !defined S_ISDIR
#define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
#endif
#endif
taken from here: c - Error: identifier "_S_IFDIR" is undefined - Stack Overflow[^]
|
|
|
|
|
googling s_isdir windows gives this hit: Porting To Win32!!!!. Seems like what you want. If not, maybe one of the other 27,000 results might help?
|
|
|
|
|
|
Hi.
I send a "TEXT" from Form1 to Form2.
Sometimes it's good, sometimes it's not good.
When you send "TEXT" from Form1 to Form2, TEXT disappears from Form2.show.
---------------------------------------------
Hide Expand Copy Code
Form1.h
private Burron1()
{
Form2::Form fm;
fm.viewText();
}
Form2.h
namespace Form {
public class Form
{
Form2()
{
void viewText();
}
}
}
void viewText()
{
textBox1->Text="TEXT";
}
-------------------------------------------------------------
Only when Text's Form, no problem. I cann't see other , only did mySql. This disappeared the "TEXT". textBox->Text is a Empty. I sent "TEXT" can't look for any.
I want to know how to make the appearing thing.
Say me , please.
Thank you.
|
|
|
|
|
private Burron1()
{
Form2::Form fm;
fm.viewText();
}
You create a local instance of Form2 in the above method, and then call viewText . But as soon as you return from that method, the variable fm goes out of scope and the form is destroyed. You need to create the form outside this method so it remains active until you decide to destroy it.
|
|
|
|
|
Is it a native or managed c++ code? 
|
|
|
|
|
I am a newbie to C++ programming and currently working on a program using Abstract Factory design pattern and linked list to store the objects and display them.
The user is expected to select whether the entry is for a management staff or Junior staff then save the parameters in the linked list and display them too.
I have created the abstract factories and the linked list but I am stuck on how to save the objects and display them with the linked list.
I need help with how to pass the staff object to the linked list and display them.
The AddNode and PrintList functions of the Linked list aren't working. (StaffMain.cpp).
Thank you.
I have five files - Staff.h, Staff.cpp, StaffList.h, StaffList.cpp and StaffMain.cpp
The codes are below
Staff.h
<pre>#pragma once
#include<string>
class Staff
{
private:
std::string Name;
std::string Address;
int age;
public:
Staff() {
Name = "";
Address = "";
age = 0;
}
Staff(std::string zName, std::string zAddress, int zage)
{
Name = zName;
Address = zAddress;
age = zage;
}
virtual void display() = 0;
virtual void input() = 0;
};
class JuniorStaff : public Staff {
private:
std::string Name;
std::string Address;
int age;
std::string staffLevel;
public:
JuniorStaff() {
Name = "";
Address = "";
age = 0;
staffLevel = "";
}
void input();
void display();
};
class MgtStaff : public Staff { private:
std::string Name;
std::string Address;
int age;
std::string mgrLevel;
public:
MgtStaff() {
Name = "";
Address = "";
age = 0;
mgrLevel = "";
}
void input();
void display();
};
class StaffFactory
{
public:
virtual Staff* staffDetails() = 0;
};
class JuniorStaffFactory :public StaffFactory
{
public:
Staff* staffDetails()
{
return new JuniorStaff();
}
};
class MgtStaffFactory :public StaffFactory
{
public:
Staff* staffDetails()
{
return new MgtStaff();
}
};
Staff.cpp
#include<iostream>
#include<string>
#include"Staff.h"
using namespace std;
void Staff::input()
{
}
void Staff::display()
{
cout << "The staff name is " << Name << endl;
cout << "The address of staff is " << Address << endl;
cout << "The staff age is " << age << "years" << endl;
}
void JuniorStaff::input()
{
cout << "Enter staff name: " << endl;
cin.ignore();
getline(cin, Name);
cout << "Enter address of staff: " << endl;
cin.ignore();
getline(cin, Address);
cout << "Enter staff age: " << endl;
cin.ignore();
cin >> age;
cout << "Enter staff level: " << endl;
cin.ignore();
getline(cin, staffLevel);
}
void JuniorStaff::display()
{
cout << "The staff name is " << Name << endl;
cout << "The address of staff is " << Address << endl;
cout << "The staff age is " << age << "years" << endl;
cout << "The staff level is " << staffLevel << endl;
}
void MgtStaff::input()
{
cout << "Enter staff name: " << endl;
cin.ignore();
getline(cin, Name);
cout << "Enter address of staff: " << endl;
cin.ignore();
getline(cin, Address);
cout << "Enter staff age: " << endl;
cin.ignore();
cin >> age;
cout << "Enter Management level: " << endl;
cin.ignore();
getline(cin, mgrLevel);
mgrLevel = mgrLevel;
}
void MgtStaff::display()
{
cout << "The staff name is " << Name << endl;
cout << "The address of staff is " << Address << endl;
cout << "The staff age is " << age << "years" << endl;
cout << "The Manager level is " << mgrLevel << endl;
}
StaffList.h
#pragma once
#include"Staff.h"
class List {
private:
class Node {
friend class List;
StaffFactory* newstaff;
Node* next;
public:
Node()
{
this->newstaff = NULL;
this->next = NULL;
};
Node(StaffFactory* c, Node* n)
{
this->newstaff = c;
this->next = n;
}
};
List::Node* head;
List::Node* curr;
public:
List();
void AddNode(StaffFactory* c);
void PrintList();
};
StaffList.cpp
#include<iostream>
#include<string>
#include"StaffList.h"
#include"Staff.h"
using namespace std;
List::List() {
head = NULL;
curr = NULL;
}
void List::AddNode(StaffFactory* c) {
List::Node* n = new List::Node;
n->next = NULL;
n->newstaff = c;
if (head == NULL) {
head = n;
}
else
{
curr = head; while (curr->next != NULL)
{
curr = curr->next;
}
curr->next = n;
}
}
void List::PrintList() {
curr = head;
while (curr != NULL) {
curr->newstaff->staffDetails();
curr = curr->next;
}
}
StaffMain.cpp
#include <iostream>
#include<string>
#include"Staff.h"
#include"StaffList.h"
using namespace std;
int main()
{
List stafflist;
int choice;
cout << "Select type of staff: " << endl;
cout << "1: Junior Staff" << endl;
cout << "2: Management Staff" << endl;
cout << "Selection: ";
cin >> choice;
cout << endl;
StaffFactory* newStaff;
switch (choice)
{
case 1:
newStaff = new JuniorStaffFactory;
break;
case 2:
newStaff = new MgtStaffFactory;
break;
default:
cout << "Invalid selection!!!" << endl;
newStaff = NULL;
break;
}
if (newStaff != NULL)
{
Staff* c = newStaff->staffDetails();
c->input();
c->display();
stafflist.AddNode(newStaff);
Staff* d = newStaff->staffDetails();
d->input();
stafflist.AddNode(newStaff);
stafflist.PrintList();
}
}
|
|
|
|
|
EjireK wrote: The AddNode and PrintList functions of the Linked list aren't working. You will need to be much more specific than that. Exactly what does "not working" mean, and where in the code do the failures occur.
As a quick exercise you could write a simple linked list that holds basic types (integers for example) and work on that until you can see exactly how to make it work correctly. You can then adapt that skeleton to handle any object type. Next step is to create the basic staff type and process objects of that type into the list. Finally you can expand it to add the other child types. Taking things a step at a time is much better, and easier, than trying to create a full system in one go.
|
|
|
|
|
For clarity, my challenge is with passing the abstract factory class object to the Linked list to create the node and to display it. The program does not generate any error currently as it successfully prompts the user to select which type of staff to create then prompts the user to specify the parameters.The linked list works with creation of staff object without the abstract factory but the exercise specifies states that I should use abstract factory with linked list to save the staff objects and display it. I’ve been unable to use the linked list with the abstract factory class object. I think my problem is in the StaffMain.cpp where I’m to specify the factory object to pass to the linked list but can’t seem to get that working. Thank you.
|
|
|
|