characterName issue

Hello experts. Sorry for the very basic question. I have started C++ now but I dont have any coding knowledge even in my academics. So please bare with me.
I m practising C++ by watching youtube videos.
While I am doing same as he do, I cant change the value in the middle.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

int main()
{
    string characterName = "Shiva";
    int characterAge;
    characterAge = 30;
    cout << "This is my name " << characterName << endl;
    cout << "My age " << characterAge << " years old" << endl;
    
    characterName = "Santosh";
    cout << characterName << " Love badminton" << endl;
    cout << "At this age " << characterAge << " Can play easily." <<endl;

    return 0;
}


Please let me know the issue
characterName = "Santosh";

That changes fine. It works.
Last edited on
No man its not working :(
What IDE, operating system and compiler are you using?

Can you show us an example of the output you are seeing?
Last edited on
IDE: Codeblocks
WS: 10

Output:

This is my name Shiva
My age 30 years old
Shiva Love badminton
At this age 30 Can play easily.

Process returned 0 (0x0) execution time : 0.033 s
Press any key to continue.
It is unfortunately typical that users of Codeblocks must exit the IDE, then relaunch it before rebuilding.

It seems it doesn't "realize" it must re-link after changes to source code. It isn't every rebuild, either. Unknown what conditions may cause it, but it is widely reported.

See if that's impacting you.
Last edited on
Some traps to look out for.
- Check no previous version of your program is running - Windows won't let you overwrite a .exe if it's still running.
- You're actually saving the latest edit.
- You're compiling the latest edit.
- Check your build output log tabs to see if there are any missed error messages.
- You're running the version you compiled - watch out for compiling debug and running release say.
- Your anti-virus s/w isn't quarantining any new version of the .exe you create. Consider adding an 'exclude directory' rule to your AV s/w which excludes your entire development tree.
- Quit and restart C::B. Sometimes, it just ties itself up in a knot.

Your code works for me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ cat foo.cpp
#include <iostream>

using namespace std;

int main()
{
    string characterName = "Shiva";
    int characterAge;
    characterAge = 30;
    cout << "This is my name " << characterName << endl;
    cout << "My age " << characterAge << " years old" << endl;

    characterName = "Santosh";
    cout << characterName << " Love badminton" << endl;
    cout << "At this age " << characterAge << " Can play easily." <<endl;

    return 0;
}
$ g++ foo.cpp
$ ./a.out 
This is my name Shiva
My age 30 years old
Santosh Love badminton
At this age 30 Can play easily.
You are right @Niccolo
Data has not saved. I restarted and open the file. New changes are not saved even after I press the save button.

Thanks for the help.

@saleem. Thanks for the inputs man. I will remember that also for future issues.
similar issues on other compilers, where the compiler can't tell that you modified code and keeps the old version to save time compiling. Most have a rebuild all that forces it to all work right, so you don't have to restart/exit but keep it in the back of your mind.
Topic archived. No new replies allowed.