|
TCHAR* fpath=_T("C:\\WINDOWS");
if(PathIsDirectoryW(fpath)==TRUE)
cout<<"Is a directory"<
|
|
|
|
|
kcynic wrote: if(PathIsDirectoryW(fpath)==TRUE)
Have you tried:
if (PathIsDirectoryW(fpath) != FALSE)
... kcynic wrote: ...but it does not work.
Which means what?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
use this code this will work actually this function returns some value but not TRUE if direstory exists else it returns 0
TCHAR* fpath=_T("C:\\WINDOWS");<br />
if(PathIsDirectory(fpath))<br />
cout<<"Is a directory"<<endl;<br />
Regards,
Pankaj Sachdeva
"There is no future lies in any job"
"but"
"future lies in the person who holds the job"
|
|
|
|
|
I you want to use of a directory and also your are not sure its exist or no use SetCurrentDirectory and check return value of this function.
|
|
|
|
|
kcynic wrote: I use GetFileAttributes().
But it need a wide character set string as its paramter,otherwise,it does not work.
It will work with either Unicode or ANSI builds.
kcynic wrote: Now,I want to using one byte char string as the path,
Most paths are comprised of more than one byte. Perhaps you meant something else.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Im trying to create a simple program the reads a string of integers from the board and store them in an array, then out put to the screen each integer from that string. It compiles fine but then crashes with an error. This is my code:
<br />
<br />
#include "stdafx.h"<br />
#include conio.h<br />
#include iostream<br />
using namespace std;<br />
<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
int aArray[4];<br />
int n;<br />
cout << "Input 5 digits: "; cin >> aArray[4];<br />
for ( n=0; n<0; n++ )<br />
{<br />
cout << "Integer: " << aArray[n] << endl;<br />
}<br />
<br />
_getch();<br />
return 0;<br />
}<br />
this is the error
Run-Time Check Failure #2 - Stack around the variable 'aArray' was corrupted.
|
|
|
|
|
The last element of aArray if aArray[3], but not aArray[4].
And what do you mean by:
Herboren wrote: for ( n=0; n<0; n++ )
|
|
|
|
|
forgive me I had noticed that earlier I corrected it. Edit:
<br />
<br />
#include "stdafx.h"<br />
#include <<conio.h>><br />
#include <<iostream>><br />
using namespace std;<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
int aArray[4];<br />
int n;<br />
<br />
<br />
cout << "Input 5 digits: "; cin >> aArray[0];<br />
<br />
for ( n=0; n<5; n++ )<br />
{<br />
cout << "Integer: " << aArray[n] << endl;<br />
}<br />
_getch();<br />
return 0;<br />
}<br />
of course knowing the array is 5 integers long '01234'. Basically the program is supposed to read a string of integers from the user, for example, input '12345' all together on the first line. Then each value within that string is stored in an array therefore if I wanted to print the first value of that array the value would come out as the '1' and so on. Now when you build the code it asks for an input the downside to this is it asks for 5 elements as a string or individual, in 5 different columns. so if you typed '12345' you would have to press enter and repeat that 4 more times, which is what im trying to avoid. The operation of the program is supposed to ask for the string of integers once and place each element of the string into an array therefor the string '12345' would be placed in aArray[4] thus giving me 5 elements in in one column. smell my drift?
|
|
|
|
|
The program is working fine but the logic in your code is not correct.
All you need to do is to parse the string to extract it's digits, store them in array and then print.
|
|
|
|
|
Herboren wrote: cin >> aArray[4];
NO
You have to prepare a for loop to input the 4 numbers one after the other.
Russell
|
|
|
|
|
Herboren wrote: Im trying to create a simple program the reads a string of integers
...
int aArray[4];
These two seem to contradict each other. You either meant to say, "Im trying to create a simple program the reads an array of integers," or you need to declare:
Herboren wrote: for ( n=0; n<0; n++ )
This loop will not do what you expect, unless you expect it to execute 0 times.
string aArray[4]; In any case, consider:
int aArray[4];
cin >> aArray[0];
cin >> aArray[1];
cin >> aArray[2];
cin >> aArray[3]; or
for (int n = 0; n < 3; n++)
cin >> aArray[n]; Notice the benefits of the latter example?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Russel *Sigh*, if you have a little more to tell me than just "NO" i might actually listen to you. Crow even turning it to a string wouldnt that mean its still in char format and not int. I should be able to add an unspecified amount to each element of the string inside the array. Like adding a 1 to 12345 making it 22345.
<br />
#include "stdafx.h"<br />
#include <conio.h><br />
#include <sstream><br />
#include <string><br />
#include <iostream><br />
#include <cstdlib><br />
using namespace std;<br />
<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
int aArray[4];<br />
int u,d,t,q,c,a;<br />
string st;<br />
<br />
cout << "Input 5-digits: "; cin >> st; cout << st << endl; _getch();<br />
istringstream ss(st);<br />
<br />
<br />
ss >> u;<br />
aArray[0] = u;<br />
if ( ss.peek() != '\n' )<br />
{<br />
cerr<<"Invalid format"<<endl;<br />
return EXIT_FAILURE;<br />
}ss.ignore();<br />
<br />
ss >> d;<br />
aArray[1] = d;<br />
if ( ss.peek() != '\n' )<br />
{<br />
cerr<<"Invalid format"<<endl;<br />
return EXIT_FAILURE;<br />
}ss.ignore();<br />
<br />
ss >> t;<br />
aArray[2] = t;<br />
if ( ss.peek() != '\n' )<br />
{<br />
cerr<<"Invalid format"<<endl;<br />
return EXIT_FAILURE;<br />
}ss.ignore();<br />
<br />
ss >> q;<br />
aArray[3] = q;<br />
if ( ss.peek() != '\n' )<br />
{<br />
cerr<<"Invalid format"<<endl;<br />
return EXIT_FAILURE;<br />
}ss.ignore();<br />
<br />
ss >> c;<br />
aArray[4] = c;<br />
cout << u << d << t << q << c << " "<br />
<< aArray[0] <br />
<< aArray[1]<br />
<< aArray[2]<br />
<< aArray[3]<br />
<< aArray[4]<br />
<< endl;<br />
cout << aArray[0] << endl;<br />
_getch();<br />
return 0;<br />
}<br />
<br />
-- modified at 10:49 Tuesday 18th September, 2007
|
|
|
|
|
Herboren wrote: *Sigh*, dont worry bout it dude, I must not be making myself clear enough I dont know any other basic way to put it. I got better results somewhere else. sheesh!
That's fine, but remember, you're the one asking for help, not us.
Herboren wrote: Crow even turning it to a string...
I was not suggesting using one type over another. I was merely pointing out that the type you do use ultimately determines what API/classes you need. For example, if you say you want to add a bunch of numbers together, but provide a code snippet that uses string s, there's obviously going to be extra work involved.
Herboren wrote: I should be able to add an unspecified amount to each element of the string inside the array. Like adding a 1 to 12345 making it 22345.
And how does the code snippet you've shown do any of this? What exactly are you wanting the user to input (there's a big difference between five numbers or digts, and a 5-digit number)?
This all may sound pedantic, but if we can't understand what it is that you want, how could you possibly expect an answer?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Forgive me if I may have sounded crude. I have researched google dreamincode codeguru among other search engines and did not find my answer /cry, sorry im just frustrated. This is role of my program. Think of it as a uname/pword program which leads to a basic encryption or start of it:
--role--
Please input a 5 digit number: 78265
Your input was 78265, is this correct? y
--role--
Now, knowing user input was a 5 digit number, that should then be broken down into and array of integers:
78265 Each element of the 5 digit number would be placed into an array after user input ie: 7,8,2,6,5
|
|
|
|
|
Much clearer. How about something like:
string strNumber = "78265";
int nDigits[5];
nDigits[0] = strNumber[0] - '0';
nDigits[1] = strNumber[1] - '0';
nDigits[2] = strNumber[2] - '0';
nDigits[3] = strNumber[3] - '0';
nDigits[4] = strNumber[4] - '0';
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
strNumber cannot be declared in the program. The strNumber has to ask for users input, because the number could be anything that user specifies. smell my drift? . There has to be a way to store the users input '12345' in an array after they type it in.
-- modified at 15:09 Tuesday 18th September, 2007
Here is antoher extended role
--role
Please type in a five digit number: 79135 //Ask for user input
The number you typed was'79135' is this correct? y //Is input correct y/n
The first number '7' from 79135 will be stored in aArray[0]. //store 7 in array0
The second number '9' from 79135 will be stored in aArray[1]. //store 9 in array0
The third number '1' from 79135 will be stored in aArray[2]. //store 1 in array0
The fourth number '3' from 79135 will be stored in aArray[3]. //store 3 in array0
The fifth number '5' from 79135 will be stored in aArray[4]. //store 5 in array0
Each element of the 5 digit number from user input have been stored individually in the array[5]
--role--
|
|
|
|
|
Herboren wrote: strNumber cannot be declared in the program. The strNumber has to ask for users input, because the number could be anything that user specifies. smell my drift?
Yes, and what I showed was merely an example. I'm not in the position of providing all of the cin /cout statements that you require. Even new developers know that string strNumber = "79135" can be turned into a user input-able statement with but one line of code. How a value gets assigned to a variable, either via the keyboard or as a string literal, is irrelevant.
Herboren wrote: The first number '7' from 79135 will be stored in aArray[0]. //store 7 in array0
The second number '9' from 79135 will be stored in aArray[1]. //store 9 in array0
The third number '1' from 79135 will be stored in aArray[2]. //store 1 in array0
The fourth number '3' from 79135 will be stored in aArray[3]. //store 3 in array0
The fifth number '5' from 79135 will be stored in aArray[4]. //store 5 in array0
Why would you want all five digits stored in array0 ? Furthermore, what is array0 ?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
it was supposed to say
//store in aArray[0] //example
//store in aArray[1] //example
//store in aArray[2] //example
//store in aArray[3] //example
//store in aArray[4] //example
this was only an example, this has nothing to do with my code this was just a role just so you could better understand what I was trying to say.
<quote>Yes, and what I showed was merely an example. I'm not in the position of providing all of the cin/cout statements that you require.
I know it was an exmaple and im not asking you to tell what the cin and cout is. I know I can grab sets of digits as a string, I know basically everything you just told me. I dont know any other basic way to put it, i have role played it for you twice now and you still dont seem to understand what im saying. Reverting back to the 2nd question I asked yesterday, The problem I am having is storing each e-l-e-m-e-n-t of the "string" into an a-r-r-a-y.
|
|
|
|
|
Herboren wrote: it was supposed to say
//store in aArray[0] //example
//store in aArray[1] //example
//store in aArray[2] //example
//store in aArray[3] //example
//store in aArray[4] //example
this was only an example,
And is exactly what I showed you in my code snippet.
Herboren wrote: The problem I am having is storing each e-l-e-m-e-n-t of the "string" into an a-r-r-a-y.
I've showed you how to do this twice, using two different approaches. What are you not understanding?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Holy shat dude it worked. you are the bomb digitty. Heh I knew I could get user input by doing cin >> string; which normally a string is a chain of characters I guess I should say symbols and I thought the string had to be converted to integers first before storing them into and array. yeah I know char's can be stored in arrays to but I had planned on adding different numerals to each int stored in the array, so i assumed i wouldnt be able to add numberals to char's stored in the array, thats like saying 1 + a or 2 + b which then would result in an error of some sort. But it worked perfectly all thanks to you. sorry if i may have sounded a little edgy, it was out of my perspective which is why i was not understanding.
Okay so the part I dont understand is the "- '0'" when converting the str to the array. Awesome im glad we completed that. Now here is another doosy. I need to create an array based on the amount of symbols in the str, so instead of pre.creating the 'aArray[5]' im using the strlen(str.c_str()) to count the number of symbols in the str from the users input. this is my code so far:
<br />
<br />
#include "stdafx.h"<br />
#include <string><br />
#include <iostream><br />
#include <conio.h><br />
using namespace std;<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
string str;<br />
int aArray[5];<br />
int n;<br />
<br />
cout << "Input a 5-digit number: "; <br />
<br />
<br />
cin >> str;<br />
<br />
aArray[0] = str[0] - '0';<br />
aArray[1] = str[1] - '0';<br />
aArray[2] = str[2] - '0';<br />
aArray[3] = str[3] - '0';<br />
aArray[4] = str[4] - '0';<br />
<br />
cout << "The length of " << str << " is: " << strlen( str.c_str()) << endl;<br />
<br />
_getch(); <br />
return 0;<br />
}<br />
<br />
<br />
-- modified at 17:54 Tuesday 18th September, 2007
|
|
|
|
|
Herboren wrote: cout << "The length of " << str << " is: " << strlen( str.c_str()) << endl;
Since you are using a string object:
cout << "The length of " << str << " is: " << str.length() << endl; Herboren wrote: I need to create an array based on the amount of symbols in the str, so instead of pre.creating the 'aArray[5]' im using the strlen(str.c_str()) to count the number of symbols in the str from the users input.
int *nArray = new int[what_number_goes_here?];
...
delete [] nArray;
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hi
can anybody help me regarding how to write a vc++ code for opening,closing and saving an image???It would be great if anyone is having code for this..
Thanks & Regards,
Ravan
|
|
|
|
|
|
You do realize there are MANY image file formats, right?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
And see CXImage class on the codeproject.
|
|
|
|