473,796 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with microsoft C compiler doesn`t accept things gcc does,how to solve? (encoding)

Here is the example code.

int main(int argc, char *argv[])
{
string Result;
WIN32_FIND_DATA daten;
HANDLE h = FindFirstFile(T EXT("c://test"), &daten);
system("PAUSE") ;
return EXIT_SUCCESS;
}

It works fine with DevCpp and gcc.

The error with microsoft C compiler is that he can`t convert from string
to LPCSTR.

I think the problem is inside the encoding, ansi, unicode, ... Found
some ways to avoid this error but all are not very awesome.

Please tell me the best way to solve this.
Jul 16 '07
17 4106
On Jul 17, 8:08 pm, "Bo Persson" <b...@gmb.dkwro te:
sun1991 wrote:

:::: The error with microsoft C compiler is that he can`t convert
:::: from string to LPCSTR.
:::
::: std::string Hi( "Hello" );
::: LPCSTR pHi = &Hi.at(0); // pick one
::: char const *pHi2 = &Hi.at(0);
::: LPCSTR pHi3 = Hi.c_str();
:: Is it right? I thought Hi.c_str() returns a temporary c-string, it
:: will be gone when pHi3 try to dereference it?

It returns a pointer to a C-string (which might be a copy of Hi's
content). The pointer is valid as long as Hi isn't potentially
modified.

Bo Persson
Well, I did a little experiment:

int _tmain(int argc, _TCHAR* argv[])
{
{
std::string s("I'm a test string");
const char* ptr = s.c_str();
s = "Another test string";

printf("%s\n", ptr);

}
system("pause") ;
return 0;
}

And the result is: Another test string
---
So what I said above was wrong, looks like it actually returns a RAW
const char* ptr, point to the internal buffer of string. I don't think
c_str() will create a copy, if so, who should handle the delete action
on this copy?

Thanks!
Jul 18 '07 #11
"Michael Reichenbach" <Re*********@di scardmail.comwr ote in message
news:f7******** **@aioe.org...
Ok. You got me. :) It`s was not the real code. I always try to cut down my
problem to a minimum so it`s more easy to figure out.

Here is a new example code. I tested it. It works in DevCpp but not in
Visual Studio.

#include <stdlib.h>
#include <windows.h>

int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(" c://test", &FindFileDat a);
system("PAUSE") ;
return EXIT_SUCCESS;
}
This doesn't compile in MS VC++ .net 2003 without proper compile switches:

#include <windows.h>

int main()
{
}

Try a vc newsgroup.
Jul 18 '07 #12
sun1991 wrote:
:: On Jul 17, 8:08 pm, "Bo Persson" <b...@gmb.dkwro te:
::: sun1991 wrote:
:::
::::::: The error with microsoft C compiler is that he can`t convert
::::::: from string to LPCSTR.
::::::
:::::: std::string Hi( "Hello" );
:::::: LPCSTR pHi = &Hi.at(0); // pick one
:::::: char const *pHi2 = &Hi.at(0);
:::::: LPCSTR pHi3 = Hi.c_str();
::::: Is it right? I thought Hi.c_str() returns a temporary c-string,
::::: it will be gone when pHi3 try to dereference it?
:::
::: It returns a pointer to a C-string (which might be a copy of Hi's
::: content). The pointer is valid as long as Hi isn't potentially
::: modified.
:::
::: Bo Persson
::
:: Well, I did a little experiment:
::
:: int _tmain(int argc, _TCHAR* argv[])
:: {
:: {
:: std::string s("I'm a test string");
:: const char* ptr = s.c_str();
:: s = "Another test string";
::
:: printf("%s\n", ptr);
::
:: }
:: system("pause") ;
:: return 0;
:: }
::
:: And the result is: Another test string
:: ---
:: So what I said above was wrong, looks like it actually returns a
:: RAW const char* ptr, point to the internal buffer of string. I
:: don't think c_str() will create a copy, if so, who should handle
:: the delete action on this copy?

The standard allows c_str to return a pointer to the string's internal
buffer, or to some other buffer. That is up to the implementation.
There is no explicit requirement to have an internal buffer, in the
first place. .-)

After you modify s, the ptr is no longer valid, so using it in printf
is undefined. Anything could happen!

If c_str would return a pointer to some other buffer, the string class
would be required to somehow manage that. In practice, this doesn't
happen as all known implementations have an internal buffer, and
returns a pointer to it. In the next edition of the standard, C++09,
this will most likely be required.
Also, if you assign a much longer string to s, it might have to
reallocate the buffer and you ptr will definitely point into nowhere.
Bo Persson
Jul 18 '07 #13
joe
On Jul 16, 7:45 pm, Michael Reichenbach <Reichenb...@di scardmail.com>
wrote:
Ok. You got me. :) It`s was not the real code. I always try to cut down
my problem to a minimum so it`s more easy to figure out.

Here is a new example code. I tested it. It works in DevCpp but not in
Visual Studio.

#include <stdlib.h>
#include <windows.h>

int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(" c://test", &FindFileDat a);
system("PAUSE") ;
return EXIT_SUCCESS;

}- Hide quoted text -

- Show quoted text -
You do realize that "C://test" is an illegal path, don't you? Did you
perhaps mean "C:\\test" ? Or possibly "C:/test" ?

I can believe that gnu has some broken path translation layer blindly
converting '/'s to '\'s so that may explain why it works under gnu and
not VC.

joe

Jul 18 '07 #14
On Jul 17, 10:57 am, "Default User" <defaultuse...@ yahoo.comwrote:
Michael Reichenbach wrote:
Ok. You got me. :) It`s was not the real code. I always try to cut
down my problem to a minimum so it`s more easy to figure out.

That's a good idea, but what you post has to be a complete program.
Here is a new example code. I tested it. It works in DevCpp but not
in Visual Studio.
#include <stdlib.h>
#include <windows.h>
int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(" c://test", &FindFileDat a);
system("PAUSE") ;
return EXIT_SUCCESS;
}

This compiled on gcc?

gcct.c:2:21: windows.h: No such file or directory
gcct.c:7: warning: data definition has no type or storage class
gcct.c:8: error: `FindFileData' undeclared here (not in a function)
gcct.c:8: error: initializer element is not constant
gcct.c:8: warning: data definition has no type or storage class
gcct.c:9: error: parse error before string constant
gcct.c:9: warning: data definition has no type or storage class

Brian
Sorry, but now you're just being stupid. There's two possibilities
here.

1) You are on an operating system other than Windows, in which case
you have got to be a complete idiot to think that #include <windows.h>
will work
2) You are on windows, in which case you have got to be a complete
idiot to not know how to compile programs for windows.

Please point me to the location in the FAQ that says that every code
fragment people post must be a complete working program, and compile
on every theoretical combination of platform and compiler.

If you're not smart enough to figure out that a) the program applies
to Windows only, and b) how to use the -I option of GCC, then perhaps
you aren't qualified to answer questions about C++ in the first place.

Jul 18 '07 #15
Zachary Turner wrote:
On Jul 17, 10:57 am, "Default User" <defaultuse...@ yahoo.comwrote:
>Michael Reichenbach wrote:
>>Ok. You got me. :) It`s was not the real code. I always try to cut
down my problem to a minimum so it`s more easy to figure out.

That's a good idea, but what you post has to be a complete program.
>>Here is a new example code. I tested it. It works in DevCpp but not
in Visual Studio.
>>#include <stdlib.h>
#include <windows.h>
>>int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(" c://test", &FindFileDat a);
system("PAUSE") ;
return EXIT_SUCCESS;
}

This compiled on gcc?

gcct.c:2:21: windows.h: No such file or directory
gcct.c:7: warning: data definition has no type or storage class
gcct.c:8: error: `FindFileData' undeclared here (not in a function)
gcct.c:8: error: initializer element is not constant
gcct.c:8: warning: data definition has no type or storage class
gcct.c:9: error: parse error before string constant
gcct.c:9: warning: data definition has no type or storage class

Brian

Sorry, but now you're just being stupid. There's two possibilities
here.

1) You are on [..]
It does not matter what the possibilities are. The program is OS-
specific and the alleged behaviour is compiler-specific, so there is
no way to answer it from the language point of view. The FAQ does
contain a list of suggested newsgroups to post to to have platform-
and/or compiler-specific questions answered.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 18 '07 #16
joe
On Jul 16, 7:45 pm, Michael Reichenbach <Reichenb...@di scardmail.com>
wrote:
Ok. You got me. :) It`s was not the real code. I always try to cut down
my problem to a minimum so it`s more easy to figure out.

Here is a new example code. I tested it. It works in DevCpp but not in
Visual Studio.

#include <stdlib.h>
#include <windows.h>

int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(" c://test", &FindFileDat a);
system("PAUSE") ;
return EXIT_SUCCESS;
I am probably stating the obvious, but "c://test" isn't a valid path.
Now, "c:\\test" or "c:/test" is, but I don't know of anywhere that two
forward slashes are valid.

I never did see where you defined what doesn't work meant though.

joe
Jul 19 '07 #17
On Jul 18, 2:17 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Zachary Turner wrote:
On Jul 17, 10:57 am, "Default User" <defaultuse...@ yahoo.comwrote:
Michael Reichenbach wrote:
Ok. You got me. :) It`s was not the real code. I always try to cut
down my problem to a minimum so it`s more easy to figure out.
That's a good idea, but what you post has to be a complete program.
>Here is a new example code. I tested it. It works in DevCpp but not
in Visual Studio.
>#include <stdlib.h>
#include <windows.h>
>int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(" c://test", &FindFileDat a);
system("PAUSE") ;
return EXIT_SUCCESS;
}
This compiled on gcc?
gcct.c:2:21: windows.h: No such file or directory
gcct.c:7: warning: data definition has no type or storage class
gcct.c:8: error: `FindFileData' undeclared here (not in a function)
gcct.c:8: error: initializer element is not constant
gcct.c:8: warning: data definition has no type or storage class
gcct.c:9: error: parse error before string constant
gcct.c:9: warning: data definition has no type or storage class
Brian
Sorry, but now you're just being stupid. There's two possibilities
here.
1) You are on [..]

It does not matter what the possibilities are. The program is OS-
specific and the alleged behaviour is compiler-specific, so there is
no way to answer it from the language point of view. The FAQ does
contain a list of suggested newsgroups to post to to have platform-
and/or compiler-specific questions answered.
I agree, but please understand that the fact that people are posting
to a newsgroup in the first place can -sometimes- (not always, but
sometimes) be an indicator that the person posting the question is not
exactly an expert on the topic they're posting about. In such cases,
it is very easy for someone to misunderstand the problem and think the
issue lies with something else. Rather than degrade such people and
intentionally toy with them, either cut to the chase and tell them to
post in a different group, or just answer the question.

In this case, it appears to have been a legitimate mistake. Something
compiled with gcc but not visual c. To someone who has very little
experience with windows programming, this can just as easily have been
a) a bug in visual c, b) a bug in gcc (it wasn't supposed to compile
but gcc accepted it anyway), or c) a platform specific problem. In
fact, for someone who is beginner to mid level, c may not even be an
apparent choice at first.

Jul 19 '07 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5623
by: trexim | last post by:
Hi, I am trying to create a Web Reference for CSTA using the URL http://www.ecma-international.org/standards/ecma-348/csta-wsdl/csta-wsdl-all-operations.wsdl Visual .Net complains that: " The document was understood, but it could not be processed. - The WSDL document contains links that could not be resolved. - There was an error downloading
18
6178
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the strcat (mystract). Program below. However this appears not to have fixed the problem and I don't know why it shouldn't ? Any further help as to what else I am doing wrong will be appreciated regards
5
2346
by: Hari | last post by:
Guys please help me to solve this strange problem what Iam getting as follows.. Trying to instantiate a global instance of a template class as follows :- when i build this code with debug and run this works fine. but if build in unicode release or release this does't work. IS THERE ANY PROBLEM OF INSTANTIATING TEMPLATE CLASSES
4
4580
by: Alex Sibilev | last post by:
Hello, I have a really weird problem I've been trying to solve it without any luck for the last couple of hours :( I'm writing a "conference board" application (quite similar to ASP.NET forum). I don't use server controls in it (apart from Page). The problem occurs on the page where visitor can post a new messages. Basically, it's a form with couple of
5
8632
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file". Same file path containing special characters works fine in one machine, but doesn't work in other. I am using following API function to get short file path. Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As
16
4930
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be easily verified: Implement the following in a web service method (just raises a SOAPException with a...
2
7056
by: Peter2 | last post by:
Hi, I have a problem posting non-ASCII characters in FORM fields between classic ASP and ASP.NET. I use a fully patched Windows 2000 Advanced Server with .net 2.0 and visual Studio 2005 installed, IIS, IE6 etc ... When an *.ASPX page receives the post, it drops non-ASCII characters, for example it drops character é from word Montréal. Specifying explicit encoding on ASP/ASPX page doesn't help. The encoding works without doing anything...
3
3447
by: Rene | last post by:
Hello to all! For a long time I have been "fighting" a problem compiling an OpenGL program which uses GLUT. First I have put a question in a Watcom group (I want to use this compiler) to which I got no reply, in an OpenGL group somebody recommended me to use Visual C++ which I did. That worked OK but I do would like to use Watcom. In the meantime I found solutions to several of the errors I got but one is left which I cannot find a...
159
7134
by: bernard | last post by:
howdy! please recommend a good c compiler. - should be small - should be fast - should come with a good ide - should be inexpensive i am using windows os.
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10221
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.