Thread: forgot about Concatenating strings... need help

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    19

    Question forgot about Concatenating strings... need help

    forgot about concatenating and i cant find my old files to review about it :P

    anyways my plan is just to add input of str1 with .txt...

    I dont mind people correcting me, just please be noob friendly

    the output is like:
    Code:
    Output: sample.txt
    Sorry about the noob codes... i just got back to coding... its like a year now LOL
    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<stdio.h>
    
    main()
    {
    char str[100],str1[10],str2;
    clrscr();
    str2=(".txt");
    cout<<"1: ";
    cin>>str1;
    
    str=str1+str2;
    
    cout<<"Output: "<<str;
    
    getch();
    return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    18
    Quote Originally Posted by jazzglenn421 View Post
    forgot about concatenating and i cant find my old files to review about it :P

    anyways my plan is just to add input of str1 with .txt...

    I dont mind people correcting me, just please be noob friendly

    the output is like:
    Code:
    Output: sample.txt
    Sorry about the noob codes... i just got back to coding... its like a year now LOL
    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<stdio.h>
    
    main()
    {
    char str[100],str1[10],str2;
    clrscr();
    str2=(".txt");
    cout<<"1: ";
    cin>>str1;
    
    str=str1+str2;
    
    cout<<"Output: "<<str;
    
    getch();
    return 0;
    }


    Try using STL strings

    Code:
    string str1;
    
    cin >> str1;
    str1 += ".txt";
    cout << str1 << endl;

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    19
    Quote Originally Posted by CodeMonkey62 View Post
    Try using STL strings

    Code:
    string str1;
    
    cin >> str1;
    str1 += ".txt";
    cout << str1 << endl;
    thanks man
    but there's a slight problem

    http://img685.imageshack.us/img685/4...inghappend.png

    the compiler doesnt recognize "string", so i placed "char" instead, problems reduced to 1 more... and what is on the image is the last 1

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I would suggest that you get a more up to date compiler. You could try Code::blocks or one of the free Microsoft compilers.


    Jim

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    18
    Quote Originally Posted by jazzglenn421 View Post
    thanks man
    but there's a slight problem

    http://img685.imageshack.us/img685/4...inghappend.png

    the compiler doesnt recognize "string", so i placed "char" instead, problems reduced to 1 more... and what is on the image is the last 1
    std::string is an STL class, so should not be a problem. You would probably have to include the header

    #include <string>

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Update your compiler. You are writing non-standard compliant ISO C++ code. The fact that your compiler allows this means it's broken.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Strings under the STL?
    By laserlight in forum C++ Programming
    Replies: 9
    Last Post: 07-19-2007, 02:55 AM
  2. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  3. Problem with Strings, Please help!
    By varus in forum C++ Programming
    Replies: 8
    Last Post: 11-27-2006, 11:47 PM
  4. Help w/ comparings two strings case sensitive
    By ikkin in forum C Programming
    Replies: 7
    Last Post: 11-13-2003, 08:26 AM
  5. concatenating two strings
    By js_badboy in forum C Programming
    Replies: 2
    Last Post: 09-08-2003, 08:27 PM