Author Topic: problem with MS Visual C++ 2010  (Read 2210 times)

0 Members and 1 Guest are viewing this topic.

Offline Chef

  • Peasant
  • *
  • Posts: 126
  • Cookies: 3
  • Corrupted Soul
    • View Profile
problem with MS Visual C++ 2010
« on: June 22, 2013, 08:34:06 pm »
Could someone explain how to use this software?
I been writing code but my main problem is I don't know how to compile or execute it.
I'm trying to change the value/meaning of a string during execution. From the tutorial I believe I'm doing it correctly but I get a error!
 
The error is: Error 1 error C2374: 'mystring' : redefinition; multiple initialization
The second error is: Error 2 error C2088: '<<' : illegal for class
What am I doing wrong?

 
Code: [Select]
#include <iostream>
 
#include <string>
 
using namespace std;
 
int main ()
   
{
  string mystring = "How does this executed code look?";
   
cout << mystring << endl;
  string mystring = "My code is different now!";
   
cout << mystring << endl;
  return 0;
   
}
« Last Edit: June 22, 2013, 08:40:02 pm by Kulverstukas »
"To find happiness is to not always laugh."

Offline bluechill

  • Cybermancer
  • Royal Highness
  • ****
  • Posts: 682
  • Cookies: 344
  • I am the existence in these walls
    • View Profile
Re: MS Visual C++ 2010
« Reply #1 on: June 22, 2013, 08:39:44 pm »
Could someone explain how to use this software?
I been writing code but my main problem is I don't know how to compile or execute it.
I'm trying to change the value/meaning of a string during execution. From the tutorial I believe I'm doing it correctly but I get a error!
 
The error is: Error 1 error C2374: 'mystring' : redefinition; multiple initialization
The second error is: Error 2 error C2088: '<<' : illegal for class
What am I doing wrong?

 
Code: [Select]
#include <iostream>
 
#include <string>
 
using namespace std;
 
int main ()
   
{
  string mystring = "How does this executed code look?";
   
cout << mystring << endl;
  string mystring = "My code is different now!";
   
cout << mystring << endl;
  return 0;
   
}

1st error is because you cannot redefine the same variable twice.  Ie. once you define 'mystring' you can't do another 'string mystring' or 'int mystring' etc. in the same scope.  The second error is because it doesn't know the type of 'mystring' since you tried to redefine it.  Basically just remove the 'string' keyword/class from 'string mystring = "My code is different now!";'
I have dreamed a dream, but now that dream has gone from me.  In its place now exists my own reality, a reality which I have created for myself by myself.

Offline Chef

  • Peasant
  • *
  • Posts: 126
  • Cookies: 3
  • Corrupted Soul
    • View Profile
Re: problem with MS Visual C++ 2010
« Reply #2 on: June 22, 2013, 09:25:32 pm »
Okay I see now.

I figured out how to execute my codes on MS Visual C++ 2010. It's called "Start Debugging". Correct me if I'm wrong.
Well when it displays my codes output in the cmd. The cmd only stays open for like 0.5 of a second. I don't even get a chance to really see what the output of my input coding was. Is this normal or did I tinker something incorrectly?
« Last Edit: June 22, 2013, 10:35:31 pm by Chef »
"To find happiness is to not always laugh."

Offline theifyppl

  • Serf
  • *
  • Posts: 44
  • Cookies: 20
    • View Profile
Re: problem with MS Visual C++ 2010
« Reply #3 on: June 22, 2013, 10:37:52 pm »
Personally, I like to use Code::Blocks as an IDE instead of MS Visual Studio, but to execute code there should be compile/build options somewhere in the menu. After you compile & build the program, there should be an execute option as well. Search around the menu for them.

The start debugging option is for debugging your programs. Debugging is the process of removing any bugs/errors/etc. that may be in your code.
« Last Edit: June 22, 2013, 10:39:53 pm by theifyppl »

Offline bluechill

  • Cybermancer
  • Royal Highness
  • ****
  • Posts: 682
  • Cookies: 344
  • I am the existence in these walls
    • View Profile
Re: problem with MS Visual C++ 2010
« Reply #4 on: July 26, 2013, 02:26:11 pm »
Executing a program is done by using the shortcut CTRL + F5 (in VS). Debugging and executing are two different scenarios.

If a program terminates, it should close down. Visual Studio won't keep it open the way Code::Blocks does.

I generally ask for user input at the end _getch() before the return value via #include <conio.h>
I was told I should find a better alternative, since my method is platform-dependent.

Yes it is.  But here's a platform independent way:

http://www.cplusplus.com/reference/cstdio/getchar/
I have dreamed a dream, but now that dream has gone from me.  In its place now exists my own reality, a reality which I have created for myself by myself.