|
Hi all, im trying to create a function that reads a file. The idea of this is to enter a specific file you'd like to have the program read and list the contents of the file. But if you enter the wrong information the else function will tell you that its a wrong entry.
Here's what i have so far:
<br />
#include <fstream><br />
using namespace std;<br />
<br />
int main(){<br />
char file[]="file.txt";<br />
printf("Enter a file you would like to read: ");<br />
scanf("%s", file);<br />
if(strcmp(file, "file.txt")){<br />
printf("Reading contents of file: %s\n",file);<br />
}<br />
else{<br />
printf("That is not a valid file.\n");<br />
}<br />
<br />
system("pause");<br />
<br />
return 0;<br />
}<br />
It doesnt do what it looks like. and im dying to know what i did wrong. Any suggestions? Thanx in advance!
|
|
|
|
|
This is wrong forum to ask this question. Use VC++ forum instead.
dellthinker wrote: if(strcmp(file, "file.txt")){
printf("Reading contents of file: %s\n",file);
}
you need to modify this to,
if(strcmp(file, "file.txt")== 0){
printf("Reading contents of file: %s\n",file);
}
|
|
|
|
|
i am looking for help in open gl program in c++...anyone here good in that..if there is someone i will post my doubt here..
|
|
|
|
|
Do you want to use .NET, or are you in the wrong forum ? The NeHe tutorials were excellent when I read them.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi everyone,
I'm creating a WinForms program with a combination of native and managed code. When I compile the program with /clr:pure it builds and runs without problems. I'd like to use the Boost Filesystem library, but the linker complains about undefined references when /clr:pure is on. Using only /clr, the program builds fine, but when trying to run, an exception gets thrown.
The exception gets triggered by line 1473 of dbgheap.c (part of the VC runtime):
_ASSERTE(_CrtIsValidHeapPointer(pUserData));
NOTE: This only happens when using the /clr switch. It doesn't happen with /clr:pure, for example. Can anyone shed some light on this? I'm using VS.NET 2005 Prof SP1 on WinXP Prof SP2 on x86 platform.
Cheers,
Ralph
|
|
|
|
|
What does the call stack say?
|
|
|
|
|
Nishant Sivakumar wrote: What does the call stack say?
Sorry I wasn't able to respond sooner, but you know how deadlines are. Anyway, I worked around the problem by using the file & directory manipulation classes in the System::IO namespace. I'd still like to investigate this problem further when I find some time though.
Cheers,
Ralph
|
|
|
|
|
Why does the compiler complain about the following array of char* declaration?
<br />
public ref class Form1 : public SWF::Form<br />
{<br />
...<br />
private:<br />
static const char* rfDlls[] = { "rfwin32.dll", "rfi32rpc.ndr", "rfi32smb.ndr", NULL };<br />
...<br />
}<br />
Error Message:
error C4368: cannot define 'rfDlls' as a member of managed 'Configuration1::Form1': mixed types are not supported
|
|
|
|
|
Use something like this :-
static array<const char*>^ rfDlls = { "rfwin32.dll", "rfi32rpc.ndr"};
|
|
|
|
|
Thanks Nish,
PS. Looking forward to reading your book.
|
|
|
|
|
Can any body tell me what is wrong here???
fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.
|
|
|
|
|
2 things
1 - you asked in the wrong forum
2 - your file doesn't include stdafx.h, but you're using precompiled headers.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
3 - stdafx.h nust be the top most #include d header
|
|
|
|
|
toxcct wrote: stdafx.h nust be the top most #included header
Yes, but in stdafx.cpp.
Every newly created project comes with stdafx.cpp and stdafx.h
|
|
|
|
|
bsaksida wrote: Yes, but in stdafx.cpp.
not only ; in every cpp file of the project using stdafx.h as the precompiled header file
|
|
|
|
|
The file name just indicates where to stop pre-compiling - it doesn't HAVE to be called
stdafx.h 
|
|
|
|
|
Hi everyone,
I'm trying to use Jeff Atwood's Encryption class, but replicating a simple example yields lots of errors at compile time. Jeff's class is written in VB.NET, but AFAIK all .NET languages compile down to the same CIL, right? So I should be able to use it.
I've tried to rewrite the following VB.NET code in C++/CLI. Am I doing something wrong?
TIA,
Ralph
VB.NET:
<br />
Dim sym As New Encryption.Symmetric(Encryption.Symmetric.Provider.Rijndael)<br />
Dim key As New Encryption.Data("My Password")<br />
Dim encryptedData As Encryption.Data<br />
encryptedData = sym.Encrypt(New Encryption.Data("Secret Sauce"), key)<br />
Dim base64EncryptedString as String = encryptedData.ToBase64<br />
C++/CLI:
<br />
Encryption::Symmetric^ sym = gcnew Encryption::Symmetric(Encryption::Symmetric::Provider::Rijndael);<br />
Encryption::Data^ key = gcnew Encryption::Data("My Password");<br />
Encryption::Data^ encryptedData = sym->Encrypt(gcnew Encryption::Data("Secret Sauce"), key);<br />
System::String^ base64EncryptedString = encryptedData->ToBase64();<br />
|
|
|
|
|
Ralph A. Moritz wrote: I've tried to rewrite the following VB.NET code in C++/CLI. Am I doing something wrong?
Sounds like a nightmare to me.
Why not just use it out of a dll ? Or use something in the Cryptography namespace ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Christian Graus wrote: Why not just use it out of a dll ?
I've compiled Jeff's code into a DLL assembly, and I'm trying to use the encryption classes from the assembly. The problem is that when I try to create an Encryption::Symmetric object, the compiler says:
error C3673: 'EncryptionClassLibrary::Encryption::Symmetric' : class does not have a copy-constructor
Christian Graus wrote: Or use something in the Cryptography namespace ?
IMO Jeff's Encryption class is a lot simpler to use than the stuff in System::Security::Cryptography. But if I can't figure out how to get it working, I guess I'll have to use the latter.
Cheers,
Ralph
|
|
|
|
|
A copy constructor is one that takes an instance of the object, and copies the values into the class. So, just add one.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Christian Graus wrote: A copy constructor is one that takes an instance of the object, and copies the values into the class. So, just add one.
I know what a copy constructor is, but I have no idea how to create one in VB.NET or how to extend a VB.NET class in C++/CLI.
|
|
|
|
|
In VB.NET, a constructor is called new(), I think. I dunno I guess you should google it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
As far as I know, you cannot create copy constructors in VB.NET. It is possible a GC object may have been created on the stack (You have a missing "^" and "gcnew" somewhere!) when the code was converted from VB.NET.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I've given up on using Jeff's encryption library and decided to use the System::Security::Cryptography stuff instead. But just look at how much code is required to encrypt a string. Sheesh!
<br />
System::String^ EncryptString(System::String^ str) <br />
{<br />
System::IO::MemoryStream^ ms = gcnew System::IO::MemoryStream;<br />
SSC::RijndaelManaged^ rm = gcnew SSC::RijndaelManaged;<br />
SSC::CryptoStream^ cs = gcnew SSC::CryptoStream(ms, rm->CreateEncryptor(), SSC::CryptoStreamMode::Write);<br />
System::IO::StreamWriter^ sw = gcnew System::IO::StreamWriter(cs);<br />
sw->Write(str);<br />
<br />
sw->Close();<br />
cs->Close();<br />
ms->Close();<br />
<br />
array<System::Byte>^ buff = ms->ToArray();<br />
<br />
System::Text::UnicodeEncoding^ enc = gcnew System::Text::UnicodeEncoding;<br />
return enc->GetString(buff);<br />
}<br />
|
|
|
|
|
Ralph A. Moritz wrote:
array^ buff = ms->ToArray();
my code got mangled there. The above should read:
array<System::Byte>^ buff = ms->ToArray();
|
|
|
|