|
|
Keep in mind that George's solution is not the same as your original code. Most notably, you shouldn't write to any of the memory occupied by the strings, whereas with regular arrays, it's always safe to write to that memory.
|
|
|
|
|
Thanks Mike,
1. Why his solution is not the same as mine?
2. How memory corruption will occur? Could you let me know an example please? I am using the array as constant string, so I can not imagine a case which will cause memory corruption.
regards,
George
|
|
|
|
|
char s1[] = "foo";
char* s2 = "bar";
strcpy ( s1, "aaa" );
strcpy ( s2, "bbb" ); The memory pointed to by s2 should be treated as read-only.
|
|
|
|
|
Good point! Thanks Mike! I have not noticed this point before.
regards,
George
|
|
|
|
|
If you want to stick with fixed-sized array bounds, you have to specify all bounds except the first. That's why [][] is an error but [][64] is OK.
|
|
|
|
|
Thanks Mike,
Could you explain from compiler internal point of view why I need to provide the innermost size, why I can not make it empty (e.g. [][])? I think it must break some rules or make compiler confused to make proper decision to generate object code, but I can not find why.
regards,
George
|
|
|
|
|
char s1[4] = "cat";
char s2[] = "dog"; In both of those cases, the array size is 4. The compiler can deduce the size of s2 from the initializer string, which is 4 chars long.
char* s3[2] = { "hello", "bob" };
char* s4[] = { "code", "project" }; Here, the arrays contain char* . Again, the compiler can deduce the size of s4 because the initializer has two char* s.
Now make it a 2-D array (I'll switch to int s since the initializer syntax is more precise)
int i5[5][2] = { {1,2,3,4,5}, {6,7,8,9,10} }; i5 is an array of two int[5] arrays. Now if I did this:
int i6[5][] = { {1,2,3,4,5}, {6,7,8,9,10}, {0,2,4,6,8} }; Since I used three int[5] arrays in the initializer, the compiler deduces that i6 is int[5][3] . (BTW I just realized that my earlier post was wrong, it's the last dimension that you can leave out, not the first.)
|
|
|
|
|
Hi Mike,
The code,
int i6[5][] = { {1,2,3,4,5}, {6,7,8,9,10}, {0,2,4,6,8} };
will not compile.
You should use,
int i6[][5] = { {1,2,3,4,5}, {6,7,8,9,10}, {0,2,4,6,8} };
or
int i6[3][5] = { {1,2,3,4,5}, {6,7,8,9,10}, {0,2,4,6,8} };
regards,
George
|
|
|
|
|
Hello,
I would like to read a file whose name is save as a string . To read this file, i use the command file.open(string,ios::in) . But i have an error message: no matching function for call to `std::basic_fstream<char, std::char_traits<char=""> >::open(std::string&, const std::_Ios_Openmode&)'
Should i use another type to save the name of the file?
I would rather keep the command file.open() .
Thank you very much
Guillaume
|
|
|
|
|
use string.c_str() function it will return LPCTSTR string associated with stored string!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief
|
|
|
|
|
i should use strin.c_str() instead of what? what is a LPCTSTR?
could you write it. Like:
string s1;<br />
getline(list,s1);
fstream fichier1;<br />
fichier1.open(s1,ios::in);
Thank you very much
|
|
|
|
|
fichier1.open(s1.c_str(),ios::in);
|
|
|
|
|
thank you very much for your help!
|
|
|
|
|
LPCTSTR is an LPCWSTR in UNICODE builds and a LPCSTR otherwise.
A LPCSTR is a Long Pointer on a Constant STRing, a LPCWSTR a Long Pointer on a Constant Wide STRing.
All WIN32 stuff.
|
|
|
|
|
Allright thank you for this information.
|
|
|
|
|
how to read stl files in binary format using mfc?
|
|
|
|
|
saisp wrote: how to read stl files in binary format using mfc?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
|
yes i have seen this. but this code reads only ascii format files. i have to read both. if i convert binary to ascii the file is not valid one. since the string value is not there. how to convert binary to ascii
|
|
|
|
|
I dont know much about STL format, however check VTK.
There should be an example showing how to use VTK with MFC.
|
|
|
|
|
Thank you!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
|
Hi,
i have a very old project without unicode support that i wanted to modernize a bit. Especially the user interface should get the new windows xp or vista control-style. But it doesn't works completly . The Dialog Controls don't wanted to switch to the new style. I tried everything i've found in the net but nothing works. Then i created a new project (mfc-application, dialog based) where i just open a about box to start some tests. The first result was:
The Button and the Icon are drawn in XP Style
Then i compared every option in the project settings and all include-files and #defines in the stdafx.h to my own project and changed one by one to find out whats wrong.
When i changed the character set from Unicode to Multi Byte i got this dialog box:
The Button and the Icon are drawn in Old Style
I really don't understand why this switch leads to this old window styles. But the bigger problem is: my own application is written completly for Multi Byte Character Set. And its a VERY Big Application. It will take days to convert it to Unicode and since there are things like text parsers included it will not be easy to be sure that everything runs fine after the conversion.
It would be nice if there is a way to get around this problem without switching to unicode.
Does someone know this problem and how to go around?
Thanks in advance.
Best Regards,
Florian
-- modified at 5:28 Friday 27th July, 2007
|
|
|
|
|
Should have used the generic text routine mappings from the start
Is it just a manifest problem?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|