0

Im reading information from a CSV file and im getting random symbols at the start of my first input, my understanding is that compiler doesn't know where the start of the string is so looks for the first null pointer it can find in this case a comma in the CSV file, is there a way to correct this?

apologies in advance im not sure how to write the minimal code used on stack overflow and my project is due soon

#include <iostream>
#include <string.h>
#include <fstream>  
#include <sstream>  
using namespace std;

int main()
{
    string Name,Password;

    cout << "enter name\n" ;
    cin >> Name;

    cout >> "enter Password"
    cin >> Password;

    ifstream InFile('MyFile');

    string line;

    while (getline(InFile, line))
    {
        istringstream iss(line);    
        string NameIn, Password                                             

        if (getline(iss, NameIn,',') && getline(iss, Password, ','))
            if (NameIn = Name && PasswordIn == Password)
            {
                cout << "welcome " << name ;
            } 
    }
3
  • It's unclear what you are talking about. Can you add a CSV content example and add more details about your issue with such content? Commented Apr 12, 2024 at 22:22
  • The file you are reading from probably has a BOM. Open it in an editor like Notepad++ and it will tell you and allow you to save it without one. You could also hex dump the first 4 bytes. You're also missing an = here if ( NameIn = Name && PasswordIn == Password) Commented Apr 12, 2024 at 22:29
  • BOM-> Byte Order Mark. A special code telling the file reader how to interpret the multi-byte character encoding in the file. Commented Apr 12, 2024 at 22:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.