getline and char conflict?

I'm playing around with C++ and trying to make a small program that shows a variable, lets you change it, then shows you after you've overwritten it. But getline is underlined in red. It only stops being red when i comment out ; char x[256] = "Default Text";. I am using Visual Studio to develop and I would prefer if you use printf instead of cout when possible.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
int main()
{
	//int x
	; char x[256] = "Default Text";
	; printf("Current: %s\n", x)
	; string x;
	; printf("Enter Name: ");
	; getline(cin, x);
	; printf("You Entered: %s\n", x.c_str())
	; printf("Press any key to continue . . . ")
	; _getch()
	; system("cls")
	; main()
	; return 0;
}
closed account (48T7M4Gy)
Feel free to use the material in the left hand menu. In this case the Reference part, search getline

http://www.cplusplus.com/reference/string/string/getline/?kw=getline
closed account (48T7M4Gy)
Where did you sweep this code up from?
Why all the preceding ;'s
Why 2 main()'s
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main()
{
    string y; //<--
    
    char x[256] = "Default Text";
	printf("Current: %s\n", x);
	
    printf("Enter Name: ");
    getline(cin, y);
    
    strcpy( x, y.c_str());
    
    printf("You Entered: %s\n", x);
    
    printf("Press any key to continue . . . ");
    cin.get();
    return 0;
}
Current: Default Text
Enter Name: fff ggg hhh 890
You Entered: fff ggg hhh 890
Press any key to continue . . . 
 
Exit code: 0 (normal program termination)

Topic archived. No new replies allowed.