How to Read in Strings Into Array C++

A character array is a series of memory locations that can store a sentence. C++ strings are objects that belong to a special class. Each element of an array holds a single character and ends with a character called a null terminator. You can create arrays using the C++ editor Microsoft Visual Studio Express and by using the string functions "strcpy" and "strcat."

Things You'll Need

  • Microsoft Visual Studio Express
Show More

Instructions

    • 1

      Click "Start," "All Programs" and double-click "Microsoft Visual Studio Express." Click "File" and "New" to open a new C++ file editor.

    • 2

      Type "#include <string.h>" at the top of your file and press "Enter."

    • 3

      Type the following code and press "Enter": "char str1[20]; strcpy(str1,"1111")." This will declare your strings as well as assign values. Replace the values with the values you need.

    • 4

      Type the following code to put the strings into a C++ array and press "Enter":

      char str_combined[80]; strcpy(str_combined, str4]; strcat(str_combined, str3); strcat(str_combined, str5)

      This will give the array a combined value of "444433335555." Change the values to the values you need.

    • 5

      Type the following code and press "Enter" to display your C++ array:

      printf("%s",str_combined);

Related Searches:

References

Comments

Related Ads

Featured