+1 Ahmet Ertaş · November 11, 2015
Hi everyone I'm learning C++ but I have a problem .
Subject : String Array
I bought a book for C++ and I was learning from it. The codes of the book ( it use Visual 2010 C++ Express)

#include "stdafx.h"
#include <iostream>
#include <cstring>

using namespace std;
int main() {
    char a[10], b[20];
    cout << "Name: ";
    cout << "Surname: ";
    return 0;

 I'm trying but there is an error and I'm using Visual Studio 2015 is it possible the problem from that ?

Post a Reply


Oldest  Newest  Rating
0 Anson M · November 18, 2015
@Daraban Bogdan
He is using Visual Studio which uses a precompiled header "stdafx.h".
First of all, you forgot closing bracket for main.
gets is not very reliable, instead you should use cin.get();
here is your code but with cin.get() instead.

#include "stdafx.h"
#include <stdio.h>
using namespace std;
int main() {
char a[10], b[20];
cout << "Name: ";
cin.get(a, 10);
cout << "Surname: ";
cin.get(b, 10);
return 0;

cin.get has 2 parameter. the first is which member, and the second is the maximum amount of chars you want the user to be able to input before the program just discards them. 
0 Daraban Bogdan · November 11, 2015
you have a file name stdafx.h? I mean do you created that file or just copy the code from book?
0 Brandon Li · December 13, 2015
Make an empty project.
0 Ahmet Ertaş · November 20, 2015
Thanks @Anson M   i use this codes and i understand the consept thanks man..
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator