943,888 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 741
  • C++ RSS
Jul 12th, 2008
0

From DevC++ to MVS

Expand Post »
I ran into a bug on my program that I couldn't find on my own so I decided to transfer my project from Dev C++ to Microsoft Visual Studio.

In Dev I got away with

C++ Syntax (Toggle Plain Text)
  1. string sName;
  2. cin >> sName;

But MVS doesn't like doing that. What is the substitute for comparing and saving user inputed strings?

Also:

C++ Syntax (Toggle Plain Text)
  1. srand(time(0));

was what I used to grab the internal clock to create random numbers, but in visual studio, it doesn't recognize that command.

Any help is greatly appreciated
Reputation Points: 10
Solved Threads: 0
Light Poster
Shadoninja is offline Offline
37 posts
since Jul 2008
Jul 12th, 2008
0

Re: From DevC++ to MVS

To use the srand function with time(0) you must include <ctime>. Where as for the first one, I think you have to use a plain char array and then convert that to type string.

It would also help if you showed the errors MSV was giving.
Last edited by William Hemsworth; Jul 12th, 2008 at 3:43 pm.
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008
Jul 12th, 2008
0

Re: From DevC++ to MVS

Maybe the problem is in the include you need to add (#include <string>)

C++ Syntax (Toggle Plain Text)
  1.  
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std ;
  6.  
  7. int main()
  8. {
  9. string sName;
  10. cin >> sName;
  11. return 0;
  12. }
Reputation Points: 64
Solved Threads: 1
Light Poster
stewie griffin is offline Offline
35 posts
since Jul 2008
Jul 12th, 2008
0

Re: From DevC++ to MVS

Compiler errors? Perhaps post them?

Are proper header files included? And are you using these from the std namespace ?
Last edited by Dave Sinkula; Jul 12th, 2008 at 3:48 pm. Reason: Heh. Pokey.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jul 12th, 2008
0

Re: From DevC++ to MVS

Maybe the problem is in the include you need to add (#include <string>)

C++ Syntax (Toggle Plain Text)
  1.  
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std ;
  6.  
  7. int main()
  8. {
  9. string sName;
  10. cin >> sName;
  11. return 0;
  12. }
Ahh, I never knew you could do that
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008
Jul 12th, 2008
0

Re: From DevC++ to MVS

Thanks!

<ctime> and <string> were what was missing from my code. Dev C++ let me skip those for some reason.
Reputation Points: 10
Solved Threads: 0
Light Poster
Shadoninja is offline Offline
37 posts
since Jul 2008
Jul 12th, 2008
1

Re: From DevC++ to MVS

>Dev C++ let me skip those for some reason.
Now you know why it's a good idea to test your code with multiple compilers.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: inheritance problem
Next Thread in C++ Forum Timeline: libraries recommendation and info needed





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC