EvilZone
Programming and Scripting => C - C++ => : Chef 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?
#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;
}
-
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?
#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!";'
-
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?
-
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.
-
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/