Separate characters from a char to enclose each one in different variables


You see, I'm using Borland C ++ ver 5.02 (I know it's an old compiler but I'd still like to know if there's a way to end my delirium) I need my program to read the char characters and separate them into different variables afterwards of a comma, but for the moment I just need to separate the char into other variables, this is what I carry.

    char *txt[100];
    cout<<"Ingresa texto: "
    printf("%.*s", 4, txt + 10);

Any ideas or suggestions? As far as I know Borland does not stop using strings.

asked by PABLO ALEJANDRO ROSAS SANABRIA 18.03.2018 в 06:02

1 answer


As far as I know Borland does not stop using strings.



Any ideas or suggestions?

  • Use std::string , no matter how old the compiler is.
  • Main requires return type, otherwise your program does not compile.
  • Use std::getline with std::stringstream , you can ask him to cut the lines with commas ( , ).
  • Use std::cout , function std::printf is C, if you are already using std::cout before I do not understand why you change to std::printf after.
  • int main()
        std::string txt;
        std::cout << "Ingresa texto: ";
        std::cin >> txt;
        std::stringstream ss(txt);
        std::string valor;
        while (std::getline(ss, valor, ','))
            std::cout << valor << '\n';
        return 0;
    answered by 19.03.2018 в 11:26