Using net use command in C++?

C

chanchoth

Hi everybody,

I am new to C++ and I would like to use this program to give the home
directory to each user.

My program is as below:

#include "iostream.h"

int main()

{
cout << "Home Directory for this user" << endl;
system("net use H: \\TEST\Home\%username%");
return 0;
}

I've got the message as below:
--------------------Configuration: HomeDirectory - Win32 Debug-----
Compiling...
HomeDirectory.cpp
D:\HomeDirectory\HomeDirectory.cpp(10) : error C2065: 'system' :
undeclared identifier
D:\HomeDirectory\HomeDirectory.cpp(10) : warning C4129: 'H' :
unrecognized character escape sequence
D:\HomeDirectory\HomeDirectory.cpp(10) : warning C4129: '%' :
unrecognized character escape sequence
Error executing cl.exe.

HomeDirectory.obj - 1 error(s), 2 warning(s)
Thank you so much for your assistance.
 
G

Gianni Mariani

chanchoth said:
Hi everybody,

I am new to C++ and I would like to use this program to give the home
directory to each user.

My program is as below:

#include "iostream.h"

int main()

{
cout << "Home Directory for this user" << endl;
system("net use H: \\TEST\Home\%username%");

The `/` character is somthing special in C/C++ characters
and strings. If you want a true `/` character then you
need to escape it with itself.

e.g.

"net use H:\\\\TEST\\Home\\%username%"
 
I

Ioannis Vranos

chanchoth said:
Hi everybody,

I am new to C++ and I would like to use this program to give the home
directory to each user.

My program is as below:



// For std::cout
#include <iostream>

// For std::system
#include <cstdlib>

// For std::endl
#include <ostream>

int main()
{
using namespace std;

cout << "Home Directory for this user" << endl;

// I do not know "net use", however I think it should be:
system("net use H:\\TEST\\Home\\%username%");

return 0;
}
 
J

Jerry Coffin

[ ... ]
system("net use H: \\TEST\Home\%username%");

The answer has been hinted at, but not yet given correctly. You need
two backslashes in your source code to produce a single backslash.

system("net use H: \\\\TEST\\Home\\%username%");

P.S. You might want to ask on comp.os.ms-windows.programmer.win32 about
WNetAddConnection{2|3} to do the job without an external program.
 
R

Richards Noah \(IFR LIT MET\)

Ioannis Vranos said:
// For std::cout
#include <iostream>

// For std::system
#include <cstdlib>

// For std::endl
#include <ostream>

<snip>

Including <ostream> after including <iostream> is unnecessarily redundant,
don't you think?
 
M

Mike Wahler

Richards Noah (IFR LIT MET) said:
<snip>

Including <ostream> after including <iostream> is unnecessarily redundant,
don't you think?

No. 'endl' is declared by <ostream>, not <iostream>.
Many implementations' <iostream> header does #include
<ostream>, but there's no requirement that it does.
I seem to recall a recent lengthy debate about this,
here, or at alt.comp.lang.learn.c-c++.

If you need to refer to a standard library name, #include
the header that declares it. Don't depend upon possible
(or common) implementation details.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,789
Messages
2,569,634
Members
45,342
Latest member
Sicuro

Latest Threads

Top